Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

moving a bar with UIScrollViewKeyboardDismissModeInteractive

Tags:

I have a text field that I anchor to the top of the keyboard. I can't use inputAccessoryView since it's always shown. I'm able to observe keyboard hidden/shown notifications to move it up and down with the keyboard, but this doesn't appear to work with UIScrollViewKeyboardDismissModeInteractive. Is there a way to get constant feedback on the position of the keyboard to sync the animation?

like image 947
livings124 Avatar asked Oct 01 '13 14:10

livings124


1 Answers

Edit: Looks like this does not work in iOS 8, guys -- Sorry! I'm also searching for a new solution

I solved this by creating a non-visible inputAccessoryView.

textView.inputAccessoryView = [[MJXObservingInputAccessoryView alloc] init]; 

The accessoryView observes its superview's frame and posts out a notification you can match.

static NSString * const MJXObservingInputAccessoryViewSuperviewFrameDidChangeNotification = @"MJXObservingInputAccessoryViewSuperviewFrameDidChangeNotification";  @interface MJXObservingInputAccessoryView : UIView @end  @implementation MJXObservingInputAccessoryView  - (void)willMoveToSuperview:(UIView *)newSuperview {     if (self.superview)     {         [self.superview removeObserver:self                             forKeyPath:@"frame"];     }      [newSuperview addObserver:self                    forKeyPath:@"frame"                       options:0                       context:NULL];      [super willMoveToSuperview:newSuperview]; }  - (void)observeValueForKeyPath:(NSString *)keyPath                       ofObject:(id)object                         change:(NSDictionary *)change                        context:(void *)context {     if (object == self.superview && [keyPath isEqualToString:@"frame"])     {         [[NSNotificationCenter defaultCenter] postNotificationName:MJXObservingInputAccessoryViewSuperviewFrameDidChangeNotification                                                             object:self];     } }  @end 
like image 91
Malcolm Jarvis Avatar answered Oct 21 '22 10:10

Malcolm Jarvis