The following problem occurs when I activate my UITextField
(better if I just show a couple images than try toUIViewwhich is nested within my
UITableViewController` as the footer.
Yikes can I just delete this question. Jeez
The following problem occurs when I activate my UITextField
(better if I just show a couple images than try toUIViewwhich is nested within my
UITableViewController` as the footer.
Yikes can I just delete this question. Jeez
As I understand the question, you are trying to shift the entire view when the UITextField becomes the first responder (i.e. adds the keyboard to the view)? If that is the case, I would add code in the UITextField delegate method:
#define VIEW_TAG 12345
#define kKeyboardOffsetY 80.0f
- (void)textFieldDidBeginEditing:(UITextField *)textField {
// get a reference to the view you want to move when editing begins
// which can be done by setting the tag of the container view to VIEW_TAG
UIView *containerView = (UIView *)[self.view viewWithTag:VIEW_TAG];
[UIView animateWithDuration:0.3 animations:^{
containerView.frame = CGRectMake(0.0f, -kKeyboardOffsetY, containerView.frame.size.width, containerView.frame.size.height);
}];
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
UIView *containerView = (UIView *)[self.view viewWithTag:VIEW_TAG];
[UIView animateWithDuration:0.3 animations:^{
containerView.frame = CGRectMake(0.0f, self.view.frame.origin.y, containerView.frame.size.width, containerView.frame.size.height);
}];
}
You don't have to use the 'viewWithTag' method, but simply need to get a reference to the container view, which can also be done by iterating through the subviews.
Adjust your tableview's height when keyboard appears.
Here's an example from a project of mine.
First: listen for keyboard events:
-(void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
//Be informed of keyboard
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardDidHideNotification object:nil];
}
#pragma mark keyboard
- (void)keyboardDidShow:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
CGSize size = [[userInfo objectForKey: UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
CGRect frame = CGRectMake(self.tableView.frame.origin.x,
self.tableView.frame.origin.y,
self.tableView.frame.size.width,
self.tableView.frame.size.height - size.height);
self.tableView.frame = frame;
}
- (void)keyboardWillHide:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
CGSize size = [[userInfo objectForKey: UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
self.tableView.frame = CGRectMake(self.tableView.frame.origin.x,
self.tableView.frame.origin.y,
self.tableView.frame.size.width,
self.tableView.frame.size.height + size.height);
}
I did it like this, its animated so it looks good.
The keyboards height is 216px and it takes .25s for it to stop.
Here is the part from my code:
-(void)textFieldDidBeginEditing:(UITextField *)textField {
if (textField.tag == 2) {
void (^a)(void) = ^(void){
[UIView animateWithDuration:.25 animations:^{
RegNrView.frame = CGRectMake(0, -216, 320, 460);
}
completion:nil];
};
[[NSOperationQueue mainQueue] addOperationWithBlock:a];
}
}
This makes the UIView and keyboard to move at the exact same time.