Reputation: 1387
I have a problem when in landscape rotation on my App. Everything moves to where I want it etc, but when the keyboard is visible, one of the text fields is covered. I have written some code that pushes the view up to resolve this. This bit of code works fine in portrait, but in landscape, the view rotates back to portrait. The code is below:
- (void)textFieldDidBeginEditing: (UITextField *)textField {
CGAffineTransform translation = CGAffineTransformIdentity;
if (textField == self.incVATField)
translation = CGAffineTransformMakeTranslation(0, -30);
[UIView beginAnimations:nil context:nil];
self.view.transform = translation;
[UIView commitAnimations];
}
Can anyone tell me how to resolve this, so that when the device in lanscape, the view just gets pushed up a little so I can still see the text field?
Thanks
Upvotes: 0
Views: 477
Reputation: 26400
When the editing of the text field begins, just adjust the frame of the view so that u can see the text.
- (void)textFieldDidBeginEditing: (UITextField *)textField {
self.view.frame = CGRectMake(x_origin,y_origin,width,height);
}
Another option:
You can also do this by making your view a sub view of scroll view and changing the content offset to the required point so that the text field is visible.
Upvotes: 1