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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With