链接: UITextField text jumps的UITextField文本跳转为前一个问题的iOS 9
简述: 我ViewController
2个UITextField
元素。当登录字段为firstResponder时,
self.passwordField.becomeFirstResponder()
登录字段中的文本跳转到左上角并返回。而且更重要的是奇怪:这个故障仅再现第一次,那么你需要重新ViewController
观察这种行为
这里是毛刺http://tinypic.com/player.php?v=6nsemw%3E&s=8#.VgVb3cuqpHx
我结束了这个视频(不适用于iOS 9工作) :
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
}
有没有人被这个bug吓住了?有什么建议么?
键盘通知处理
我的主要观点是UIScrollView的,为此,我改变底部空间,上海华盈,这样用户可以滚动甚至当键盘显示
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 {
self.scrollView.contentOffset = CGPointMake(0, offsetY)
}
})
}
func keyboardWillHide(notification : NSNotification) {
self.scrollViewBottom.constant = 0
self.view.layoutIfNeeded()
}
当我发现键盘通知的全部内容在iOS7中,8和9非常不同。所以,在iOS 9中,即使键盘不显示/隐藏,在更改firstResponder时也会发送通知。此外,当我通过点击textField来更改firstResponder(而不是敲击由我的代码处理的键盘上的Next)时,只有KeyboardWillShow通知和没有KeyboardWillHide。至于我,USERINFO有一些垃圾帧值,这里使用记录下一个按钮改变第一响应时(工作正常,无毛刺):
2015年10月7日12:54:13.870 keyboardWillHide: [ UIKeyboardFrameBeginUserInfoKey:的NSRect:{{0,352},{320,216}}, UIKeyboardCenterBeginUserInfoKey:NSPoint:{160,460}, UIKeyboardFrameEndUserInfoKey:的NSRect:{{0,568},{320,216}}, UIKeyboardCenterEndUserInfoKey :NSPoint:{160,676}, UIKeyboardAnimationDurationUserInfoKey:0.25, UIKeyboardIsLocalUserInfoKey:1,UIKeyboardBoundsUserInfoKey:NSRect: {{0,0},{320,216}},UIKeyboardAnimationCurveUserInfoKey: 7] 2015年10月7日12:54:13.896 keyboardWillShow: [UIKeyboardFrameBeginUserInfoKey:的NSRect:{{0,352},{320,216}}, UIKeyboardCenterBeginUserInfoKey:NSPoint:{160,460}, UIKeyboardFrameEndUserInfoKey:的NSRect :{{0,352},{320,216}}, UIKeyboardCenterEndUserInfoKey:NSPoint:{160,460}, UIKeyboardAnimationDurationUserInfoKey:0.25, UIKeyboardIsLocalUserInfoKey:1,UIKeyboardBoundsUserInfoKey:的NSRect: {{0,0},{320 ,216}},UIKeyboardAnimationCurveUserInfoKey:7]
在这里,当我在第二文本字段抽头登录:
2015-10-07 12:55:13。879 keyboardWillShow:[UIKeyboardFrameBeginUserInfoKey:的NSRect:{{0,352}, {320,216}},UIKeyboardCenterBeginUserInfoKey:NSPoint:{160, 460},UIKeyboardFrameEndUserInfoKey:的NSRect:{{0,352},{320, 216}},UIKeyboardCenterEndUserInfoKey:NSPoint:{160,460},
UIKeyboardAnimationDurationUserInfoKey:0.25, UIKeyboardIsLocalUserInfoKey:1,UIKeyboardBoundsUserInfoKey:的NSRect: {{0,0},{320,216}},UIKeyboardAnimationCurveUserInfoKey:7]
分辨率
我发现我有另一个键盘控制器,它接收键盘通知并制作一些动画。这就是基于你编辑的问题,我可以看到这一点,当你点击键盘上的一个按钮,问题在于
如何处理键盘?你有注册的键盘通知会出现/隐藏?如果是,你可以在那里发布你的代码吗? – haluzak
Tnx的帮助,检查编辑后 – user3237732
你越来越会隐藏通知,因为你在becomeFirstResponder()之前调用resignFirstResponder(),“跳跃”是由keyboardWillShow() – haluzak