我正在使用UIKeyboardWillShowNotification在調用鍵盤時向上和向下滾動視圖。這在大多數情況下工作正常。但是,鍵盤上有一個可以產生UIAlert的完成按鈕。沒有UIAlert就沒有問題,但是如果UIAlert被稱爲scrollview時會出現一些奇怪的事情,它似乎停止工作,並且變得越來越小。UIKeyboardWillShowNotification和UIAlert
這是我使用的代碼:
func adjustInsetForKeyboardShow(show: Bool, notification: NSNotification) {
guard let value = notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue else { return }
let keyboardFrame = value.CGRectValue()
let adjustmentHeight = (CGRectGetHeight(keyboardFrame) + 70) * (show ? 1 : -1)
scrollView.contentInset.bottom += adjustmentHeight
//scrollView.scrollIndicatorInsets.bottom += adjustmentHeight
}
func keyboardWillShow(notification: NSNotification) {
if keyboardVisible == false {
adjustInsetForKeyboardShow(true, notification: notification)
keyboardVisible = true
}
}
func keyboardWillHide(notification: NSNotification) {
adjustInsetForKeyboardShow(false, notification: notification)
keyboardVisible = false
}
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
}
鍵盤則有具有下面的代碼的按鈕:
func displayAlert(title:String, message:String, view:UIViewController){
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { (action) -> Void in
}))
view.presentViewController(alert, animated: true, completion: nil)
}
的結果是給出警報,那麼當我按下確定按鈕滾動查看中斷。
誰能幫助?讓我知道如果你需要更多的代碼
嘗試在鍵盤完全關閉後調用displayAlert()函數。 – ZGski