How to constrain autorotation to a single orientation for some views, while allowing all orientations on others?

后端 未结 5 1324
孤街浪徒
孤街浪徒 2020-12-01 03:44

This question is about iOS device rotation and multiple controlled views in a UINavigationController. Some views should be constrained to portrait orientation, and

5条回答
  •  自闭症患者
    2020-12-01 04:03

    The short answer is that you're using UINavigationController, and that won't work like you want it to. From Apple's docs:

    Why won't my UIViewController rotate with the device?

    All child view controllers in your UITabBarController or UINavigationController do not agree on a common orientation set.

    To make sure that all your child view controllers rotate correctly, you must implement shouldAutorotateToInterfaceOrientation for each view controller representing each tab or navigation level. Each must agree on the same orientation for that rotate to occur. That is, they all should return YES for the same orientation positions.

    You can read more about view rotation issues here.

    You'll have to roll your own view/controller stack management for what you want to do.

提交回复
热议问题