1、 頁(yè)面跳轉(zhuǎn),不能再ViewDidLoad中進(jìn)行,例如下面代碼:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blueColor];
SViewController *sc = [[SViewController alloc] init];
[self presentViewController:sc animated:YES completion:nil];
}
這段代碼讓人失望,不會(huì)跳轉(zhuǎn)的。把跳轉(zhuǎn)寫到別的生命周期函數(shù),或者其他事件方法中即可。
2、 第三方鍵盤高度的問題
項(xiàng)目中用到了UITextView輸入欄,但是當(dāng)鍵盤彈出來時(shí)會(huì)擋住UITextView,因此需要對(duì)鍵盤彈出進(jìn)行處理,具體做法就是監(jiān)聽系統(tǒng)發(fā)出的關(guān)于鍵盤的通知??梢杂猛粋€(gè)通知監(jiān)聽彈出和收起,也可以分別監(jiān)聽。根據(jù)通知中字典的key值可以取到鍵盤的高度,然后對(duì)frame做相應(yīng)的調(diào)整或者對(duì)約束進(jìn)行修改。
問題來了。
對(duì)于第三方輸入法,比如我用的搜狗輸入法,iOS9.3.5,iPhone5,系統(tǒng)會(huì)發(fā)出3個(gè)通知,給出3個(gè)高度,因此你會(huì)看到屏幕上方一塊黑色區(qū)域一閃而過,影響體驗(yàn)。獲取到通知內(nèi)容如下:
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,就視為第三次獲取到的值。