func keyboardWasShown(aNotification: NSNotification) {
self.view.setNeedsLayout() /* */
var info = aNotification.userInfo as NSDictionary
var kbSize = info.objectForKey(UIKeyboardFrameBeginUserInfoKey).CGRectValue().size
if self.containerViewController.frame != mainFrame! {
self.containerViewController.frame = mainFrame!
}
var aRect = self.view.frame as CGRect
aRect.size.height = aRect.size.height - kbSize.height
if CGRectContainsPoint(aRect, self.textField.frame.origin) == false {
self.textField.frame.origin.y = aRect.height - 30
}
}
为什么self.view.setNeedsLayout()函数搞砸了textField的位置?它导致textField不移动。布局更新太晚了吗?如果是这样,我该如何解决这个问题。我尝试过self.view.setLayoutIfNeeded(),但这也不起作用。