简体   繁体   中英

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:

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.

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.

Also when you use tableview.rowHeight = UITableViewAutomaticDimension , your rows adapt to new heights automatically.

You shouldn't use frame for anything else than animations, where the outcome is already what AutoLayout expects.

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.

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