hello i am using a form for data entry , some of the textfields are in the bottom of form. when i click on text fields for writing, keyboard appears and hides the fields behing it. if i make textfield first responder it hid开发者_如何学JAVAes keyboard but by doing this i am unable to do this. i want to know how it is possible that when keyboard appears, whole form should move up in the way that my last field is appearing on the op of key board thanks in advance
Add all of your view in a scroll view and set delegate of scroll view and textfield then use these delegate and method -
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
[self scrollViewToCenterOfScreen:textField];
return YES;
}
-(BOOL) textFieldShouldReturn:(UITextField *)textField{
if ([textField isEqual:txtField1])
{
[txtField2 becomeFirstResponder];
}
else if ([textField isEqual:txtField2])
{
[txtField3 becomeFirstResponder];
}
else
{
[textField resignFirstResponder];
[scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}
return YES;
}
- (void)scrollViewToCenterOfScreen:(UIView *)theView {
CGFloat viewCenterY = theView.center.y;
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
CGFloat availableHeight = applicationFrame.size.height - 200; // Remove area covered by keyboard
CGFloat y = viewCenterY - availableHeight / 2.0;
if (y < 0) {
y = 0;
}
[scrollView setContentOffset:CGPointMake(0, y) animated:YES];
}
There are several strategies you can use to do this -- most of them involve wrapping your view in a UIScrollView and scrolling to the appropriate control as it gets focus. You can find Apple's documentation on how to do this here : http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html
Follow the link for solution : http://objectivecwithsuraj.blogspot.in/2012/06/making-view-slide-up-to-make-room-for.html
精彩评论