super.viewDidLoad()
let tapGesture = UITapGestureRecognizer(target: self, action: Selector("hideKeyboard"))
tapGesture.cancelsTouchesInView = true
scrlView.addGestureRecognizer(tapGesture)
//self.navigationController!.navigationBarHidden = true
scrlView.contentSize = CGSizeMake(UIScreen .mainScreen().bounds.size.width, (regButton.frame.size.height + regButton.frame.origin.y)+20)
// Do any additional setup after loading the view.
}
func hideKeyboard() {
scrlView.endEditing(true)
scrlView .setContentOffset(CGPointMake(0, 0), animated: true)
}
@IBAction func tapped(sender: AnyObject) {
scrlView.endEditing(true)
scrlView .setContentOffset(CGPointMake(0, 0), animated: true)
}
我的隐藏键盘功能没问题。但现在我想在点击键盘上方的文本字段时更改它们的位置。
最佳答案
试试这个:
func textFieldShouldBeginEditing(textField: UITextField) -> Bool{
scrl.setContentOffset(CGPointMake(0.0, textField.center.y-120), animated: true)
}
并且您的 func hideKeyboard()
应保持不变
希望对你有所帮助
关于ios - 如何使用点击手势放置文本字段位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34606676/