您的位置:首页 > 产品设计 > UI/UE

iOS UITextField输入框随键盘弹出界面上移

2017-09-07 14:48 218 查看
//点击输入框界面跟随键盘上移

- (void)textFieldDidBeginEditing:(UITextField *)textField {

    

    CGRect frame = textField.frame;

    int offSet = frame.origin.y +
70 - (self.view.frame.size.height
- 216.0); //iphone键盘高度为216.iped键盘高度为352

    [UIView
beginAnimations:@"ResizeForKeyboard"
context:nil];

    [UIView
setAnimationDuration:0.5f];

   
//将试图的Y坐标向上移动offset个单位,以使线面腾出开的地方用于软键盘的显示

    if (offSet >
0) {

        self.view.frame =
CGRectMake(0.0f, -offSet,
self.view.frame.size.width,
self.view.frame.size.height);

        [UIView
commitAnimations];

    }

}

//输入框编辑完成以后,将视图恢复到原始状态

- (void)textFieldDidEndEditing:(UITextField *)textField {

    self.view.frame =
CGRectMake(0,
0, self.view.frame.size.width,
self.view.frame.size.height);

    

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: