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)
}
My hideKeyboard function is ok. But now I want to cahnge the position of the textfields above the keyboard when I tap on them.
try this :
func textFieldShouldBeginEditing(textField: UITextField) -> Bool{
scrl.setContentOffset(CGPointMake(0.0, textField.center.y-120), animated: true)
}
And your func hideKeyboard()
should be remain same Hope it will helpful for u
您可以将IQkeyboardmanger第三方库用于您的项目,这里是该链接, https://github.com/hackiftekhar/IQKeyboardManager
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.