0
我在UIViewController
中有這個代碼,它可以在鍵盤打開時改變視圖的高度。爲什麼視圖會自動生成動畫?
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
// Subscribe to keyboard events.
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
}
func keyboardWillShow(notification: NSNotification) {
let keyboardHeight = notification.userInfo![UIKeyboardFrameEndUserInfoKey]!.CGRectValue.height
// UIView.animateWithDuration(0.5) {
self.view.frame.size.height -= keyboardHeight
self.view.layoutIfNeeded()
// }
}
我注意到,即使沒有UIView.animateWithDuration
,視圖動畫也是如此。這是爲什麼?