【发布时间】:2017-01-19 03:45:44
【问题描述】:
我目前正在开发一个应用程序,该应用程序在一个滚动视图中包含多个文本字段和 2 个文本视图。在键盘出现时,我已经能够更改滚动视图的内容插图,以允许字段不被隐藏。我遇到的问题是我只能让它在一个硬编码字段上工作。我必须选择一个并为其设置动画。无论如何可以在keyboardWillShow 上获取发件人字段或文本视图?目前,我正在使用它并且一切正常,除了提到我必须选择一个字段detailsTxtView 并为其设置动画。有什么帮助吗?
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillShow(notification:)),name: NSNotification.Name.UIKeyboardWillShow, object: nil)
func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
let contentInsets: UIEdgeInsets? = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0)
scrollView.contentInset = contentInsets!
scrollView.scrollIndicatorInsets = contentInsets!
let goto = CGPoint(x: CGFloat(0.0), y: CGFloat(detailsTxtView.frame.origin.y + (keyboardSize.height + 40)))
scrollView.setContentOffset(goto, animated: true)
}
}
【问题讨论】:
标签: ios swift swift3 nsnotificationcenter