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
,视图动画也是如此。这是为什么?