键盘
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField*)textField
{
UIWindow * window=[[[UIApplication sharedApplication] delegate] window];
CGRectframe=[textField convertRect: textField.bounds toView:window];
intoffset = frame.origin.y- (SCREEN_HEIGHT-260.0);//iPhone键盘高度216,iPad的为352
if (IS_IPHONE_X) {
offset = frame.origin.y- (SCREEN_HEIGHT-333.0);
}
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:0.5f];
//将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示
if(offset >0)
self.view.frame=CGRectMake(0.0f, -offset,SCREEN_WIDTH,self.view.frame.size.height);
[UIView commitAnimations];
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField*)textField {
self.view.frame = CGRectMake(0, EldenNav_Sta_Height, SCREEN_WIDTH, self.view.frame.size.height);
[UIView commitAnimations];
[textFieldresignFirstResponder];
return YES;
}
网友评论