3 回答

TA貢獻1862條經驗 獲得超7個贊
我發現最適合我的一個是:
func textFieldDidBeginEditing(textField: UITextField) {
if textField == email || textField == password {
animateViewMoving(true, moveValue: 100)
}
}
func textFieldDidEndEditing(textField: UITextField) {
if textField == email || textField == password {
animateViewMoving(false, moveValue: 100)
}
}
func animateViewMoving (up:Bool, moveValue :CGFloat){
let movementDuration:NSTimeInterval = 0.3
let 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()
}
您還可以更改高度值。如果要對所有文本字段使用“ if語句”,請刪除它。
您甚至可以將其用于所有需要用戶輸入的控件,例如TextView。
- 3 回答
- 0 關注
- 457 瀏覽
添加回答
舉報