UIKeyboard
来源:互联网 发布:淘宝优惠券推广渠道 编辑:程序博客网 时间:2024/06/05 10:19
其实标题是存在问题的,iOS并不提供UIKeyboard这个类的,但是提供了UIKeyboardAppearance , UIKeyboardType这种枚举类型,很显然了就是UI层面上键盘的类型罢了。另外也是这里要说的重点:
关于键盘的全局通知常量值
// Each notification includes a nil object and a userInfo dictionary containing the// begining and ending keyboard frame in screen coordinates. Use the various UIView and// UIWindow convertRect facilities to get the frame in the desired coordinate system.// Animation key/value pairs are only available for the "will" family of notification.UIKIT_EXTERN NSString *const UIKeyboardWillShowNotification;UIKIT_EXTERN NSString *const UIKeyboardDidShowNotification; UIKIT_EXTERN NSString *const UIKeyboardWillHideNotification; UIKIT_EXTERN NSString *const UIKeyboardDidHideNotification;
关于键盘的全局常量Key
UIKIT_EXTERN NSString *const UIKeyboardFrameBeginUserInfoKey NS_AVAILABLE_IOS(3_2); // NSValue of CGRectUIKIT_EXTERN NSString *const UIKeyboardFrameEndUserInfoKey NS_AVAILABLE_IOS(3_2); // NSValue of CGRectUIKIT_EXTERN NSString *const UIKeyboardAnimationDurationUserInfoKey NS_AVAILABLE_IOS(3_0); // NSNumber of doubleUIKIT_EXTERN NSString *const UIKeyboardAnimationCurveUserInfoKey NS_AVAILABLE_IOS(3_0); // NSNumber of NSUInteger (UIViewAnimationCurve)
文档中的解释已经很清楚了。这几个通知传递的是nil对象,但是包含着下面的常量Key作为userInfo字典的值。而且明确地是作为界面frame和坐标值服务的,同时动画key/values对只会对“will”通知簇有效。
接触到这一知识点是因为在学习仿微信的聊天界面的时候,点击输入框,整体界面随着键盘的上“弹”,而刚开始的想法是单纯的点击textField触发代理时间从二手动设置Frame。然而参考别人的代码,原来有这么神奇的实现:
注册通知:
-(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{ CGRect keyBoardRect = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGFloat deltaY = keyBoardRect.size.height; [UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] animations:^{ self.view.transform = CGAffineTransformMakeTranslation(0, -deltaY); }];}- (void)keyboardHide:(NSNotification *)note{ [UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] animations:^{ self.view.transform = CGAffineTransformIdentity; }];}
简单分析一下代码可以知道:通过所提供的key可以到上下偏移的偏差值deltaY(键盘的高度), 甚至还提供了键盘弹出来所需要的时间
如果缩回键盘,就是将view的transform属性设置回CGAffineTransformIdentity (相当于原点值的东西)
不过其实亲测了,动画的效果也不是很明显的
参考:动画的实现用旧的方法比较繁琐
http://www.cnblogs.com/xinus/archive/2013/01/22/ios-keybord-notification.html
0 0
- UIKeyboard
- UIKeyboard
- iOS: UIKeyboard
- UIKeyboard键盘
- UIKeyboard键盘
- UIKeyboard 键盘
- HOWTO: Customize UIKeyboard
- UIKeyboard键盘相关知识点
- UIKeyboard键盘相关知识点
- UIKeyboard and UITableView
- UIKeyboard键盘相关知识点
- UIKeyboard键盘相关知识点
- IOS UIKeyboard键盘
- UIKeyBoard高度的监控
- UIKeyBoard高度的监控
- UIKeyBoard高度的监控
- swift下获取键盘UIKeyboard
- 如何在UIKeyboard中加入定制button
- Uva-11988 - Broken Keyboard (a.k.a. Beiju Text)(链表)
- STL学习----入门(1)[unordered_set]
- Binary Tree Right Side View
- 排序算法小结
- 黑马程序员——集合(二)Set
- UIKeyboard
- 2015.8.24
- Unity实现截图功能详解
- hdoj 1052 Tian Ji -- The Horse Racing【田忌赛马,贪心】
- swift 动画
- Atlassian 产品安装、管理中出现的问题集锦
- STL学习----入门(1)[stack]
- CDH集群调优:内存、Vcores和DRF
- 关于AutoCompleteTextView实现前几个历史提示