iOS AutoLayout issue with ScrollView

后端 未结 3 1310
借酒劲吻你
借酒劲吻你 2021-01-21 11:33

Hello i have an auto layout issue with UIScrollView and ModalViewController. Here are my coding steps as sample code:

1) I have an UIView

相关标签:
3条回答
  • 2021-01-21 11:42

    Perhaps you can reset the contentoffset in the viewWillAppear? And did you already implement -(void)layoutsubviews?

    0 讨论(0)
  • 2021-01-21 11:51

    From the documentation of UIViewController's presentViewController: method:

    This method sets the presentedViewController property to the specified view controller, resizes that view controller’s view and then adds the view to the view hierarchy. The view is animated onscreen according to the transition style specified in the modalTransitionStyle property of the presented view controller.

    So the resizing of your view controller is intended. Well, by Apple, anyway.

    One way to go about this is to log the resized view's coordinates and infer what exactly has been changed. Maybe you can adjust your constraints in a way to prevent this.

    Alternatively, you could try resizing everything in the completion handler of this method.

    0 讨论(0)
  • 2021-01-21 12:05

    I think this might be a bug in iOS autolayout wrt UIScrollViews. I was having a similar problem only in my case, I would push to a detail view, then pop back to the master view which is a UIScrollView. Content in the scroll view would be shifted up. Scrolling the scroll view to the top, then pushing and popping again and things would be properly reset.

    I even tried plain out of the box master detail app using a UIScrollView instead of a table view as master, and was able to demonstrate the defect.

    Table views and Collection views do not seem to have this problem.

    0 讨论(0)
提交回复
热议问题