通过点击按钮,我将所有内容向上移动并在我正在移动的 UIView 之一中显示 UITextField:
UIView.animateWithDuration(0.7, delay: 0.0, options: .CurveEaseOut, animations: {
self.logo.frame.offset(dx: 0, dy: -200)
}, completion: nil)
UIView.animateWithDuration(0.2, delay: 0.1, options: .CurveEaseOut, animations: {
self.fill.frame.offset(dx: 0, dy: -230)
}, completion: nil)
UIView.animateWithDuration(0.3, delay: 0.5, options: .CurveEaseOut, animations: {
self.form.frame.offset(dx: 0, dy: -240)
self.form.alpha = 1.0
}, completion: nil)
但是当我点击 UITextfield(以 UIView 形式)并且出现键盘时,它会重置所有内容的偏移量。
如何避免?
最佳答案
我猜你正在使用 AutoLayout 将你的项目放在你的 View 中,它想要修复你的框架“错位”。添加带有约束的 UITextField
并更改内容约束中的值。
此外,当您使用 tableview.rowHeight = UITableViewAutomaticDimension
时,您的行会自动适应新的高度。
您不应该将 frame
用于动画之外的任何其他内容,因为动画的结果已经是 AutoLayout 所期望的。
关于ios - 当键盘出现时,它会重置内部 View 的偏移量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29692855/