【发布时间】:2015-10-22 06:39:14
【问题描述】:
我使用此代码在键盘出现时将视图向上移动,在我的登录页面中此代码运行良好,但在注册页面中它不起作用。
func textFieldDidBeginEditing(textField: UITextField) {
animateViewMoving(true, moveValue: 100)
}
func textFieldDidEndEditing(textField: UITextField) {
animateViewMoving(false, moveValue: 100)
}
func animateViewMoving (up:Bool, moveValue :CGFloat){
var movementDuration:NSTimeInterval = 0.3
var movement:CGFloat = ( up ? -moveValue : moveValue)
UIView.beginAnimations( "animateView", context: nil)
UIView.setAnimationBeginsFromCurrentState(true)
UIView.setAnimationDuration(movementDuration )
self.view.frame = CGRectOffset(self.view.frame, 0, movement)
UIView.commitAnimations()
}
我有另一个功能可以在键盘上返回键,它也可以在登录页面上工作,但不能在注册页面上。两个页面之间的所有内容都相同。
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
【问题讨论】:
-
检查您的被委托人是否已连接
-
查看演示链接:github.com/harshilkotecha/…
标签: ios swift uitextfield keyboard-events