subview assigned to the UIScrollView. when the UITextField is selected UIScrollView should move up. I tried with below code but its not working.
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
if( textField == citytextfield)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4];
//set Y according to keyBoard height
[_scrolling setFrame:CGRectMake(0.0,-220.0,320.0,460.0)];
[UIView commitAnimations];
}
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
[textField resignFirstResponder];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[_scrolling setFrame:CGRectMake(0.0,0.0,320.0,460.0)];
[UIView commitAnimations];
}
使用UIScrollView
setContentOffset
方法使其向上滚动,您需要将值50
更改为所需的值。
[_scrolling setContentOffset:CGPointMake(0,50) animated:YES];
download the tpkeyboardavoidingscrollview.
give your scrollview's class name to tpkeyboardavoidingscrollview.
@property (weak, nonatomic) IBOutlet TPKeyboardAvoidingScrollView *scrollView;
set the property and give the connection to scrollview.
In your viewcontroller.h
#import "TPKeyboardAvoidingScrollView"
then check it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.