博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uitextfield键盘遮挡问题
阅读量:2396 次
发布时间:2019-05-10

本文共 1246 字,大约阅读时间需要 4 分钟。

转载自:http://hi.baidu.com/xuen2460697/item/17e04807bed6f2873d42e265

键盘遮挡无非是要上移view,然后还原.

1
2
3
4
5
6
7
8
9
10
11
12
13
//键盘出现时,view上移
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelegate:self];
self.view.frame = CGRectMake(0, -130, 320, 460);
//130就是上移的距离
[UIView commitAnimations];
     
//键盘消失后,view还原
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelegate:self];
self.view.frame = CGRectMake(0, 0, 320, 460);
//还原
[UIView commitAnimations];
下面附上我的项目中当用uitextfield时处理键盘遮挡问题:

//chenyong textfield委托方法,当按下Return时键盘收起

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    [UIView beginAnimations:nil context:NULL];

    [UIView setAnimationDuration:0.3];

    [UIView setAnimationDelegate:self];

    self.view.frame = CGRectMake(0, 0, 320, 460);//还原

    [UIView commitAnimations];

    

    [textField resignFirstResponder];

    return YES;

}

//-(BOOL)textFieldShouldEndEditing:(UITextField *)textField

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField

{

    [UIView beginAnimations:nil context:NULL];

    [UIView setAnimationDuration:0.3];

    [UIView setAnimationDelegate:self];

    self.view.frame = CGRectMake(0, -130, 320, 460);//130就是上移的距离

    [UIView commitAnimations];

    

    return YES;

}

你可能感兴趣的文章
使用Turbine聚合监控
查看>>
Zuul案例、常见使用方式
查看>>
SpringCloudConfig--ConfigServer从本地读取配置文件
查看>>
构建高可用的Config Server、使用Spring Cloud Bus刷新配置
查看>>
Nginx——重写与重定向
查看>>
Nginx——防盗链的配置
查看>>
TCP——粘包/拆包
查看>>
ChannelHandler和ChannelPipeline
查看>>
Netty——传输API
查看>>
Netty——ByteBuf的API
查看>>
Netty——ChannelHandler和ChannelPipeline
查看>>
Netty——ChannelHandlerContext
查看>>
Netty——EventLoop和线程模型
查看>>
Camera 图像处理原理分析- 色彩篇 二
查看>>
Camera 图像处理原理分析- 色彩篇 三
查看>>
Camera 图像处理原理分析- 亮度及曝光控制
查看>>
Camera 图像处理原理分析- 抗噪 变焦 频闪 等
查看>>
c语言核心技术 二
查看>>
udev文件系统的使用和基本工作原理分析
查看>>
快速理解Docker - 容器级虚拟化解决方案
查看>>