Reputation:
Apple apps like Mail, Contacts, and SMS make the UIKeyboard appear as part of the view. The UIKeyboard slides in with the view instead of appearing as a separate animation. I have tried to recreate the same behavior calling [myTextField becomeFirstResponder]
in different places like viewWillAppear:animated
, viewDidLoad
, loadView
, navigationController:willShowViewController:animated:
but nothing works.
I read in a post (couldn't find the post now) that this seems impossible to do when you want the UIKeyboard to appear with an UITableView. However, this conclusion seems inconsistent with the Apple apps. Can someone confirm?
Is there a solution?
Upvotes: 1
Views: 2345
Reputation: 10096
It is not the private feature of Apple SDK. In iOS 7 (or any other version before) you can make a simple thing in loadView, viewDidLoad or viewWillAppear
[yourTextView performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0.0];
In this case you will get left-to-right appearance of the keyboard aligned with the motion of pushing view controller. Note that any direct call of becomeFirstResponder gives the standard animation from bottom at least in iOS 7.
Upvotes: 0
Reputation: 5026
Which SDK are you building for? I might be wrong, but I thought Apple said something about improving the behavior of pushing view controllers onscreen and the behavior of other animations.
For what it's worth, I've got this working on my project by calling becomeFirstResponder
on my UISearchBar instance in viewWillAppear:
. I'm building against the 3.1 SDK.
Upvotes: 2
Reputation: 24466
You can mimic this functionality by resizing your view frames in an animation block when you get a UIKeyboardWillShowNotification notification. Say you have a text field view in the bottom of your view like the SMS app has when it first displays an SMS conversation. When your text field gets a tap, the UIKeyboardWillShowNotification gets triggered at which point you can animate that view like this:
[UIView beginAnimations:nil context:NULL];
[textFieldView setFrame:CGRectMake(0.0f, 416.0f, 320.0f, 216.0f)];
// Also resize your table view
[tableView setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 372.0f)];
[UIView commitAnimations];
You can then reset your view frames if you get a UIKeyboardWillHideNotification notification.
I didn't figure out the exact positions of the frames here, so you'll have to calculate that yourself, but this should give you the basic idea. Just think in terms of where you want your view frames to be after the animations and just set the frames inside an animation block (i.e. -beginAnimations, -commitAnimations).
Best regards.
Upvotes: 1
Reputation: 16941
The keyboard as we iPhone Devs may use it appears in its own UIWindow
, so it will always slide up from the bottom, no matter which view-acrobatics you make in your app.
The Apple Apps obviously have access to enhanced functionality of the keyboard which we may not (yet) use.
Upvotes: 1