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?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
Malcolm's answer will work for iOS 8 and 7 with only a minor tweak. I do not have enough reputation to comment on his post so this is added as a community wiki for people needing a solution that works for iOS 7 and 8.
Header
Implementation
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.
The accessoryView observes its superview's frame and posts out a notification you can match.
This works for me:
Register for the keyboard did hide notification:
UIKeyboardDidHideNotification
.In
viewDidLoad
add the toolbar to the bottom of the view, usingaddSubview
.I use a textView so in
textViewShouldBeginEditing
I set the inputAccessoryView.Then in the keyboard did hide method, adjust the frame of the toolbar, set the inputAccessoryView to nil, and IMPORTANT, add the toolbar as a subview of the view again.
There's a much simpler way to anchor something to the keyboard. You just need to implement these methods and iOS will handle it for you.
Here's a good tutorial breaking it down more
Have you tried DAKeyboardControl?
You can see source code for handling keyboard frame on this control.
I found a solution (albeit somewhat of a hack) where I implement scrollViewDidScroll to listen to the panGestureRecognizer built into the UITableView. It turns out that the top of the keyboard stays perfectly even with the swiping finger throughout the gesture, so you can just continuously update your textfield to stay just above the panning finger.
Then I also register for Notifications
And handle them like so