1、 页面跳转,不能再ViewDidLoad中进行,例如下面代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blueColor];
SViewController *sc = [[SViewController alloc] init];
[self presentViewController:sc animated:YES completion:nil];
}
这段代码让人失望,不会跳转的。把跳转写到别的生命周期函数,或者其他事件方法中即可。
2、 第三方键盘高度的问题
项目中用到了UITextView输入栏,但是当键盘弹出来时会挡住UITextView,因此需要对键盘弹出进行处理,具体做法就是监听系统发出的关于键盘的通知。可以用同一个通知监听弹出和收起,也可以分别监听。根据通知中字典的key值可以取到键盘的高度,然后对frame做相应的调整或者对约束进行修改。
问题来了。
对于第三方输入法,比如我用的搜狗输入法,iOS9.3.5,iPhone5,系统会发出3个通知,给出3个高度,因此你会看到屏幕上方一块黑色区域一闪而过,影响体验。获取到通知内容如下:
2016-09-02 15:20:20.752 [2898:1049771] {
UIKeyboardAnimationCurveUserInfoKey = 7;
UIKeyboardAnimationDurationUserInfoKey = "0.25";
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 0}}";
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 568}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 568}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 568}, {320, 0}}";
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 568}, {320, 0}}";
UIKeyboardIsLocalUserInfoKey = 1;
}
2016-09-02 15:20:21.005 [2898:1049771] {
UIKeyboardAnimationCurveUserInfoKey = 7;
UIKeyboardAnimationDurationUserInfoKey = 0;
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 216}}";
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 568}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 460}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 568}, {320, 0}}";
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 352}, {320, 216}}";
UIKeyboardIsLocalUserInfoKey = 1;
}
2016-09-02 15:20:21.125 [2898:1049771] {
UIKeyboardAnimationCurveUserInfoKey = 7;
UIKeyboardAnimationDurationUserInfoKey = 0;
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 256}}";
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 460}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 440}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 352}, {320, 216}}";
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 312}, {320, 256}}";
UIKeyboardIsLocalUserInfoKey = 1;
}
3次获取到的高度是0,216,256。
解决办法,只使用第三次获取的值。具体操作有很多,我采用UIKeyboardFrameEndUserInfoKey获取到的高度减去UIKeyboardFrameBeginUserInfoKey获取到的高度,差值小于100,并且高度大于0,就视为第三次获取到的值。