iOS Rotate View Controller when Modal View Control

2020-07-18 10:39发布

I have an UIViewController A which opens another modal UIViewController B on UIButton action.

My Question is: When the current modal UIViewController B is open and did rotate - the previous UIViewController A doesn't rotate at all. This implies that when I dismiss UIViewController B - UIViewController A is still in the old state (has still the old interface orientation). Currently I am forcing A to rotate by calling a method in A when B rotates.

Is there another common way to inform other view controllers about rotation? Or what would be the proper way?

3条回答
We Are One
2楼-- · 2020-07-18 11:25

If the presentation style for your modal view is set to current context, it should rotate the view controller A. I had the problem but couldn't figure out why, it appears the settings in interface builder were overriding the ones set in code.

Try that, you can change the transition style obviously

IB Modal View Controller settings

查看更多
闹够了就滚
3楼-- · 2020-07-18 11:27

If you're using iOS 6, then you have (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation. Then, you just have to return the superview's device orientation.

Edit : if you're covering iOS 5, you can also check this.

查看更多
Evening l夕情丶
4楼-- · 2020-07-18 11:42

I was having a lot of issues with rotation myself. Have found a solution for all but the root view to first view.

See: Rotation issue from the first view (splash) to first viewController

This is really just notification of a device orientation change. The "libraryTableBorder" is specific to my app. Replace the code inside of the "if" and "else" to what is appropriate for your app.

查看更多
登录 后发表回答