登陆注册页面文本框UITextField被键盘遮挡的问题

最近做项目开发,遇到了一个ios初学者都会遇到的问题,就是文本框被键盘遮盖了,而ios系统又不会自动给你换位置,这纠结我一段时间,先看一个百度出镜率比较高的方法

```

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

    floatoffset =0.0f;

    if(self.verificationCodeBox.textField == textField || self.phoneBox.textField == textField){

        offset = -180.0f;

        NSTimeIntervalanimationDuration =0.30f;

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

        [UIViewsetAnimationDuration:animationDuration];

        floatwidth =self.view.frame.size.width;

        floatheight =self.view.frame.size.height;

        CGRectrect =CGRectMake(0.0f, offset , width, height);

        self.view.frame= rect;

        [UIView commitAnimations];

    }

}

```

```

-(BOOL)textFieldShouldReturn:(UITextField *)textField

{

    [textFieldresignFirstResponder];

    return YES;

}

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

    floatoffset =0.0f;

    if(self.verificationCodeBox.textField == textField || self.phoneBox.textField == textField){

    NSTimeIntervalanimationDuration =0.30f;

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

    [UIViewsetAnimationDuration:animationDuration];

    floatwidth =self.view.frame.size.width;

    floatheight =self.view.frame.size.height;

    CGRectrect =CGRectMake(0.0f, offset+64, width, height);

    self.view.frame= rect;

    [UIView commitAnimations];

    }

}

```




使用后的
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容