简体   繁体   English

出现键盘时,它会重置内部视图的偏移量

[英]When keyboard appears it resets offset of inside views

By tapping on button I'm moving everything up and show UITextField in one of UIViews I'm moving: 通过点击按钮,我将所有内容向上移动,并在我要移动的一个UIViews中显示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)

But when I'm tapping on UITextfield (in form UIView) and keyboard appears it resetting offset of everything. 但是,当我点击UITextfield(以UIView的形式)并出现键盘时,它将重置所有内容的偏移量。

How to avoid it? 如何避免呢?

I guess you are using AutoLayout to place your items inside your view, which wants to fix your frame "misplacement". 我猜您正在使用自动版式将项目放置在视图内,该视图想修复框架“错位”。 Add the UITextField with constraints and change the values in your constraints on your contents. 添加具有约束的UITextField并更改内容约束中的值。

Also when you use tableview.rowHeight = UITableViewAutomaticDimension , your rows adapt to new heights automatically. 同样,当您使用tableview.rowHeight = UITableViewAutomaticDimension ,行会自动适应新的高度。

You shouldn't use frame for anything else than animations, where the outcome is already what AutoLayout expects. 除了动画,您不应将frame用于任何其他东西,动画的结果已经是AutoLayout所期望的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM