Reputation: 28720
is there any way to move some textfield in a simple UIView up so that they could not be hide behind the keyboard.? is it possible without using UIScrollView
Upvotes: 2
Views: 3455
Reputation: 29160
It should be possible just be adjust the frame position of the view the UITextField is on. check out this code:
http://iphoneincubator.com/blog/tag/uitextfield
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[self scrollViewToCenterOfScreen:textField];
}
- (void)scrollViewToCenterOfScreen:(UIView *)theView {
CGFloat viewCenterY = theView.center.y;
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
CGFloat availableHeight = applicationFrame.size.height - keyboardBounds.size.height; // Remove area covered by keyboard
CGFloat y = viewCenterY - availableHeight / 2.0;
if (y < 0) {
y = 0;
}
scrollView.contentSize = CGSizeMake(applicationFrame.size.width, applicationFrame.size.height + keyboardBounds.size.height);
[scrollView setContentOffset:CGPointMake(0, y) animated:YES];
}
Upvotes: 3