监听键盘通知
2015-09-30 15:17
846 查看
// 2.监听键盘的通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil]; /** * 当键盘改变了frame(位置和尺寸)的时候调用 */ - (void)keyboardWillChangeFrame:(NSNotification *)note { // 设置窗口的颜色 self.view.window.backgroundColor = self.tableView.backgroundColor; // 0.取出键盘动画的时间 CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; // 1.取得键盘最后的frame CGRect keyboardFrame = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; // 2.计算控制器的view需要平移的距离 CGFloat transformY = keyboardFrame.origin.y - self.view.frame.size.height; // 3.执行动画 [UIView animateWithDuration:duration animations:^{ self.view.transform = CGAffineTransformMakeTranslation(0, transformY); }]; } /* UIKeyboardAnimationCurveUserInfoKey = 7; // 动画的执行节奏(速度) UIKeyboardAnimationDurationUserInfoKey = "0.25"; // 键盘弹出\隐藏动画所需要的时间 UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 216}}"; UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 588}"; UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 372}"; UIKeyboardFrameChangedByUserInteraction = 0; // 键盘弹出 UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 480}, {320, 216}}";// 键盘刚出来那一刻的frame UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 264}, {320, 216}}"; // 键盘显示完毕后的frame // 键盘隐藏 UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 264}, {320, 216}}"; UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 480}, {320, 216}}"; */ - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; }
相关文章推荐
- POJ 3237 - Tree(树链剖分)
- 在执行批处理时将执行错误的语句记录下来并写到日志文件中去
- EJB3 事务控制
- 购物车 购买数量的加减
- Android实现复制粘贴功能
- DefaultServlet int Tomcat
- Mac 软件“Android 文件传输 v1.0”
- Git 常用指令
- proc 多线程操作oracle
- [创意标题] spoj 11354 Amusing numbers
- LianLianKan - HDU 4272(状态压缩)
- ZOJ 3469 Food Delivery (区间DP,经典)
- AJAX局部更新演出排期
- UML概览
- flume学习(六):使用hive来分析flume收集的日志数据
- iOS UITableView(表格)
- Win7中的路由转发配置实验
- 演出排期JavaScript
- iOS runtime
- DOM对象和jQuery对象之间的相互转换