2017-08-28 97 views
6

測試我的應用程序在iOS 11測試版7 - 它似乎像鍵盤不推高內容如果我的UIViewController。UIKeyboardWillShowNotification問題與ios 11測試版7

的代碼看起來是這樣的(因爲iOS7工作):

- (void)handleNotification:(NSNotification*)notification { 
if (notification.name == UIKeyboardWillShowNotification) { 
    CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; 
    nextButtonALBottomDistance.constant = keyboardSize.height + initialPhoneBottomDistance; 
    codeBottomViewALBottomDistance.constant = keyboardSize.height + initialCodeBottomDistance; 
    double animationDuration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; 
    [UIView animateWithDuration:animationDuration animations:^{ 
     [self.view layoutIfNeeded]; 
    }]; 
} 
else if (notification.name == UIKeyboardWillHideNotification) { 
    nextButtonALBottomDistance.constant = initialPhoneBottomDistance; 
    codeBottomViewALBottomDistance.constant = initialCodeBottomDistance; 
    double animationDuration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; 
    [UIView animateWithDuration:animationDuration animations:^{ 
     [self.view layoutIfNeeded]; 
    }]; 
} 

}

足夠有趣 - 當我按下home鍵(最小化的應用程序),並重新打開它(沒有殺死它) - 佈局是固定的。

它看起來像一個iOS 11測試版的bug,但到目前爲止我還找不到任何參考。

很高興知道別人是否有這個問題。

+2

用'UIKeyboardframeenduserinfokey'替換'UIKeyboardFrameBeginUserInfoKey' –

+0

好像在工作!非常感謝@AdityaSrivastava! – Gil

+0

很高興爲您效勞 –

回答

9

使用UIKeyboardFrameEndUserInfoKey,因爲該鍵用於包含CGRect的NSValue對象,該對象標識屏幕座標中鍵盤的結束幀。做不使用UIKeyboardFrameBeginUserInfoKey

1

我也遇到了這個非運動問題。我懷疑開始&結束幀總是不正確的,因爲他們是相同或幾乎相同,但最近在iOS 11中修復,因此打破了很多代碼,它們並沒有真正理解這兩個幀之間的差異。

根據這些信息,在這裏 https://stackoverflow.com/a/14326257/5282052

開始是鍵盤開始過什麼看起來像,其中大部分不會想。 End是鍵盤看起來像什麼樣子的結果,大多數人只關心它。

[[[通知用戶信息] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue] .size;

確實通過滾動視圖的ZERO移動解決了我的問題。

3

如果您正在使用UIKeyboardFrameBeginUserInfoKey鍵讓鍵盤高度,以UIKeyboardFrameEndUserInfoKey更換,以獲得正確的鍵盤高度。

在iOS 11中,UIKeyboardFrameBeginUserInfoKey密鑰的幀的高度值爲0,因爲它是開始幀。爲了得到實際的高度,我們需要結束幀,結束幀由UIKeyboardFrameEndUserInfoKey返回。

請參考管理鍵盤documentation

UIKeyboardFrameBeginUserInfoKey的 鍵用於容納 的CGRect標識開始幀鍵盤在屏幕座標的 一個NSValue對象。 這些座標沒有考慮到 帳戶因爲界面方向更改導致 對窗口內容應用 的任何旋轉因子。 因此,可能需要向 矩形轉換爲窗口座標(使用 的convertRect:fromWindow:方法),使用它 之前或 查看座標(方法使用 convertRect:fromView)。

UIKeyboardFrameEndUserInfoKey關鍵 用於容納 的CGRect標識結束幀鍵盤在屏幕座標的 一個NSValue對象。 這些座標沒有考慮到 帳戶因爲界面方向更改導致 對窗口內容應用 的任何旋轉因子。 因此,可能需要向 矩形轉換爲窗口座標(使用 的convertRect:fromWindow:方法),使用它 之前或 查看座標(方法使用 convertRect:fromView)。