如何让view随着键盘移动
2015-11-23 20:29
495 查看
常见的一个功能,让控件随着Keyboard上下移动而移动,实现方法很多,下面是一个比较方便的方法:
#pragma mark - 键盘改动的时候其他view随着变化 -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardHide:) name:UIKeyboardWillHideNotification object:nil]; } -(void)keyboardShow:(NSNotification *)note { NSLog(@"show"); CGRect keyBoardRect=[note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGFloat deltaY=keyBoardRect.size.height; [UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] animations:^{ self.yourview=CGAffineTransformMakeTranslation(0, -deltaY); }]; } -(void)keyboardHide:(NSNotification *)note { NSLog(@"hide"); [UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] animations:^{ self.yourview = CGAffineTransformIdentity; }]; }//点击返回键
相关文章推荐
- 【Unity】场景异步加载的进度条制作
- group by和order by配合使用注意
- 检查ios设备上是否安装了某些app
- web_find()和web_reg_find()区别
- Android Matrix
- cassandra单节点的安装与配置——cassandra总结(二)
- UVA 11992 线段树
- HttpSession和jsp中session的区别(转)
- 简单工厂模式
- Flume笔记--source端监听目录,sink端上传到HDFS
- Bootstrap历练实例:小的按钮
- <<易货>>项目Postmortem结果
- Oracle卸载
- 动态规划训练(1)题解
- Android Studio中Spinner控件的数据绑定实现
- android做客户端连接web服务器
- javascript面向对象
- 设计模式 - 创建型模式 - 原型模式
- 项目部署到tomcat时报错jar not loaded. See Servlet Spec 2.3, section 9.7.2.
- 1012. 数字分类 (20)