当容器视图弹出时,我有一个UITextField在容器视图中消失。在同一个容器视图中是一个UICollectionView,其自定义单元格包含一个UITextField,并且键盘对它们工作正常。当UITextField弹出键盘时,UIView消失
我在动画函数中打印出容器视图的框架,该框架由keyboardWillShow
调用,并且容器视图的框架对于两种情况都是相同的,因此它看起来像容器视图刚好消失(而不是“未移动”正如我所想)当选择特定的UITextField时。相关的代码是:
func keyboardWillShow(notification: NSNotification) {
if let userInfo = notification.userInfo {
if let keyboardSize = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
kbHeight = keyboardSize.height
self.animateDurationView(true)
}
}
}
func keyboardWillHide(notification: NSNotification) {
self.animateDurationView(false)
}
func animateDurationView(up: Bool) {
var movement = up ? -kbHeight : kbHeight
println(movement)
UIView.animateWithDuration(0.3, animations: {
self.durationView.frame = CGRectOffset(self.durationView.frame, 0, movement)
println(self.durationView.frame)
})
}
的截图可以在这个主题中找到:KeyboardWillShow only moves container UIView for certain UITextFields
编辑:在这一点上,我几乎可以肯定,那就是与我拧自动布局约束。
是您的文本字段/ ContainerView设置,使得显示的键盘,当他们移动,从而领域没有得到覆盖由键盘(隐藏)? – BonanzaDriver
是的,这就是为什么我移动视图 – Liumx31
我有相同的情况,当我关闭AutoLayout时,它工作正常。所以我可以确认这与AutoLayout/Constraints有关 – Vincent