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
views:
1110answers:
1
Q:
Adjusting interface when keyboard appears for UITextField in a simple UIVIew without scroll view?
A:
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];
}
Dutchie432
2009-05-26 20:55:59
i want to do this without scroll view sir.. you have used scroll view
Rahul Vyas
2009-05-28 06:52:37
Just substitute the scrollView variable with your current view. I have used this code with scrollviews, views, and tableviews. The code essentially just figures out where your textfield is and calculates the animatedDistance. Use this variable to adjust your view's frame.
Dutchie432
2009-05-28 12:00:05