上一个问题的链接: UITextField文本跳转
简而言之:我有ViewController2个UITextField元素.当loginField是firstResponder之后
self.passwordField.becomeFirstResponder()
Run Code Online (Sandbox Code Playgroud)
登录字段中的文本跳转到左上角和后退.而且更奇怪的是:这个故障只是第一次再现,然后你需要重新创建ViewController才能观察到这种行为
这是故障的视频http://tinypic.com/player.php?v=6nsemw%3E&s=8#.VgVb3cuqpHx
func textFieldShouldReturn(textField: UITextField) -> Bool {
if textField === self.loginField {
self.loginField.resignFirstResponder()
// Shitty workaround. Hi, Apple!
self.loginField.setNeedsLayout()
self.loginField.layoutIfNeeded()
self.passwordField.becomeFirstResponder()
return false
}
return true
}
Run Code Online (Sandbox Code Playgroud)
是否有人被这个错误所困扰?有什么建议?
我的主视图是UIScrollView,我将底部空间更改为superview,因此即使显示键盘,用户也可以滚动所有内容
func keyboardWillShow(notification : NSNotification) {
let keyboardInfo = notification.userInfo!
let keyboardFrame = keyboardInfo[UIKeyboardFrameEndUserInfoKey]!.CGRectValue
let animDuration = keyboardInfo[UIKeyboardAnimationDurationUserInfoKey]!.doubleValue!
UIView.animateWithDuration(animDuration, animations: {
self.scrollViewBottom.constant = keyboardFrame.height
self.view.layoutIfNeeded()
let offsetY = CGRectGetMaxY(self.loginButton.frame) + 10 - self.scrollView.frame.height
if offsetY > 0 …Run Code Online (Sandbox Code Playgroud)