美文网首页
iOS UITextField输入框随键盘弹出界面上移

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

作者: 鬼才冯三郎 | 来源:发表于2021-06-29 18:29 被阅读0次

//点击输入框界面跟随键盘上移

  • (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);

}
————————————————
版权声明:本文为CSDN博主「walkerwqp」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/walkerwqp/article/details/77881499

相关文章

网友评论

      本文标题:iOS UITextField输入框随键盘弹出界面上移

      本文链接:https://www.haomeiwen.com/subject/kqukultx.html