【问题标题】:How to handle Autolayout constraints while Pedictive Text is Enabled/Disabled on Keyboard如何在键盘上启用/禁用预测文本时处理自动布局约束
【发布时间】:2017-08-08 06:20:21
【问题描述】:
这就是我的用户界面:
- 2 个文本字段,例如 tfA 和 tfB(tfA 显示预测文本,而 tfB 不显示)
- 一个位于键盘正上方的 UIButton(此按钮使用自动布局,并被限制为值为 0 的底部布局指南)
我发现问题的用例:
当我在 TextField 之间切换时,由于为 tfA 而不是为 tfB 启用了预测文本,我在来回动画时看到一个小故障,如下所示:
我正在考虑以某种方式在textFieldBeginEditing Delegate 方法中处理动画。不知道我能做什么,但任何解决方案都将不胜感激。
【问题讨论】:
标签:
ios
objective-c
animation
keyboard-events
【解决方案1】:
对于登录建议没有意义。
使用以下设置。
如果您仍然想使用它。
尝试在 inputAccessoryView 中添加您的按钮
let customView = UIView(frame: CGRectMake(0, 0, 10, 100))
customView.backgroundColor = UIColor.redColor()
customView.addSubView(btnSignIn) // add you
textFieldUsername.inputAccessoryView = customView
【解决方案2】:
您可以在视图控制器中为键盘添加观察者,如下所示:
在viewDidLoad()方法集观察者
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: .UIKeyboardWillChangeFrame
, object: nil)
并实现方法:
func keyboardWillShow(notification:Notification){
//handle keyboard frame changes here
}