Reporting incorrect bounds in landscape Mode

前端 未结 9 1104
青春惊慌失措
青春惊慌失措 2020-12-05 02:57

I am having an issue with Landscape mode in my iPad application.

I created a very small new project to show my issue I set UIInterfaceOrientation in the pList to UII

相关标签:
9条回答
  • 2020-12-05 03:33

    One of the comments on the accepted answer contained the solution to the problem for me.

    There is a method you can override on UIViewController called "viewDidLayoutSubviews", I tapped into it and adjusted my containing views from there.

    And since its called after "viewWillAppear" and before "viewDidAppear" the changes you make to the subviews show up as expected, no glitches.

    0 讨论(0)
  • 2020-12-05 03:37

    I created a small project to test frames and bounds because I was having the same problem. In fact checking for bounds on viewDidLoad resolved my issue.

    I kept digging a little bit and I found out that the bounds are also correct on viewWillLayoutSubviews method. So I guess the most "correct" way to layout your views in a project would be:

    1. alloc and instantiate them on viewDidLoad or loadView with frames that you think it's correct by that time.

    2. re-layout your created views on viewWillLayoutSubviews so they are on the correct position when the view actually appear.

    0 讨论(0)
  • 2020-12-05 03:41

    viewWillAppear (according to Paul Hegarty's CS193p lectures) is for geometry-related initializations. Since viewDidAppear follows viewWillAppear it makes sense that the bounds are correct here as well. The views bounds are not yet set in viewDidLoad.

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