Leaving inputAccessoryView visible after keyboard is dismissed
It's done like this:
Assign your UIToolbar to a property in your view controller:
@property (strong, nonatomic) UIToolbar *inputAccessoryToolbar;
In your top view controller, add these methods:
- (BOOL)canBecomeFirstResponder{
return YES;
}
- (UIView *)inputAccessoryView{
return self.inputAccessoryToolbar;
}
And then (optionally, as it usually shouldn't be necessary), whenever the keyboard gets hidden, just call:
[self becomeFirstResponder];
That way, your inputAccessoryToolbar will be both your view controller's and your text view's input accessory view.
Leaving inputAccessoryView visible after keyboard is dismissed iOS8?
iOS8 has a retain cycle with the inputAccessoryView. Here's a good post that seems to have a good workaround:
http://derpturkey.com/uitextfield-docked-like-ios-messenger/
InputAccessoryView docked at bottom
I was just shown "the" solution by Jason Foreman (@threeve). On your view controller (yes, view controller) add inputAccessoryView:
and return the view you want to dock at the bottom and move with the keyboard. It just works. The view doesn't actually need to be in your view hierarchy it will be inserted by the view controller automatically.
edit: also implement canBecomeFirstResponder and return YES (as noted by Max Seelemann). reloadInputViews can be handy too.
Why does my inputAccessoryView disappear when navigating backwards?
You may want to try calling
self.becomeFirstResponder()
in viewWillAppear
or viewDidAppear
both of them will be trigged when that happens.
How to hide inputAccessoryView without dismissing keyboard
Never found a way to alter the frame of the keyboard. Ultimately decided to forego the inputAccessoryView, add my toolbar directly to the view as a subview and animate it myself along with the keyboard directly. This keeps the two independent and so, no more line.
iPhone: How to fix inputAccessoryView to View?
I solved this by listening for Notifications and moving the toolbar up... oh well.
Something like this does the job:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
/* Listen for keyboard */
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillShow:(NSNotification *)notification
{
[keyboardToolbar setItems:itemSetFull animated:YES];
/* Move the toolbar to above the keyboard */
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect frame = self.keyboardToolbar.frame;
frame.origin.y = self.view.frame.size.height - 210.0;
self.keyboardToolbar.frame = frame;
[UIView commitAnimations];
}
- (void)keyboardWillHide:(NSNotification *)notification
{
[keyboardToolbar setItems:itemSetSmall animated:YES];
/* Move the toolbar back to bottom of the screen */
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect frame = self.keyboardToolbar.frame;
frame.origin.y = self.view.frame.size.height - frame.size.height;
self.keyboardToolbar.frame = frame;
[UIView commitAnimations];
}
I guess input accessory view is literally just meant for something stuck on top of the keyboard :)
Related Topics
Removing Object from Array in Swift 3
Cllocationmanager Responsiveness
Drawing Gradient Over Image in iOS
Dragging Scnnode in Arkit Using Scenekit
How to Use the Default iOS7 Uianimation Curve
"Unable to Validate Your Application Error" While Uploading a New Version of iOS App
Apple MACh-O Linker & Ditto Error - Xcode 8
Cannot Run Application on Simulator After Installing Xcode 11 - Cfbundleversion Error
Swift: Type Must Implement Protocol and Be a Subclass of Given Class
iPhone - Didselectrowatindexpath: Only Being Called After Long Press on Custom Cell
What the Meaning of Question Mark '' in Swift
iOS 11+ How to Migrate Existing Core Data to Shared App Group for Use in Extension
How to Animate an Svg Path in iOS
Objective-C Check If Subviews of Rotated Uiviews Intersect
App Crashes After Executing Background Fetch Completionhandler
How to Programmatically Dismiss Uialertcontroller Without Any Buttons
How to Use Uiactivityitemprovider to Send an Email with Attachment with Uiactivityviewcontroller
Uicontroleventeditingchanged Doesn't Get Fired When Using Settext of Uitextfield