0
votes

I have two view controllers (ViewController1 and ViewController2), in which ViewController1 has a modal segue to ViewController2, and ViewController2 can be dismissed back to ViewController1.

If I follow these steps:

ViewController1—rotate to landscape—modal to VC2—ViewController2—rotate to portrait—dismiss to VC1

Then, in ViewController1's viewWillAppear, I print view.frame.size and I get this (running on iPhone 6s simulator):

(667.0, 375.0)

So that means the width is longer than the height, or that it is still in landscape.

That tells me that ViewController1 hasn't rotated yet, which makes sense, since this is in viewWillAppear.

My current options (that I know of):

  1. Use viewDidAppear — not preferred since I am reloading a collection view here and the change will be noticeable.

  2. Create an unwind segue — not preferred since this requires storyboards.

So what are my other options? Is there a view controller method that will best fit my needs?

2
So it's not true that everything that can be done with storyboards can be done programmatically? I was under the impression that everything could be done programmatically.BallpointBen

2 Answers

1
votes

You are right: during viewWillAppear ViewController1's view is not yet in a window hierarchy, so it didn't have a chance to layout. In general, if you have some code to deal with layout, I may consider place it in viewWillLayoutSubviews or viewDidLayoutSubviews methods.

0
votes

You may find this answer helpful in causing ViewController1 to respond to rotation before it appears: https://stackoverflow.com/a/25667424/5496433