As the ShouldAutorotateToInterfaceOrientation
is deprecated in iOS 6 and I used that to force a particular view to portrait only, what is the correct way to do this in iOS 6? This is only for one area of my app, all other views can rotate.
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
Just go to project.plist then add Supported interface orientation and then add only Portrait (bottom home button) and Portrait (top home button).
You can add or remove there orientation as per your project requirement .
Thanks
So I ran into the same problem when displaying portrait only modal views. Normally, I'd create a
UINavigationController
, set theviewController
as therootViewController
, then display theUINavigationController
as a modal view. But with iOS 6, theviewController
will now ask the navigationController for its supported interface orientations (which, by default, is now all for iPad and everything but upside down for iPhone).Solution: I had to subclass
UINavigationController
and override the autorotation methods. Kind of lame.The answers using subclasses or categories to allow VCs within UINavigationController and UITabBarController classes work well. Launching a portrait-only modal from a landscape tab bar controller failed. If you need to do this, then use the trick of displaying and hiding a non-animated modal view, but do it in the viewDidAppear method. It didn't work for me in viewDidLoad or viewWillAppear.
Apart from that, the solutions above work fine.
IOS 5
IOS 6
I disagree from @aprato answer, because the UIViewController rotation methods are declared in categories themselves, thus resulting in undefined behavior if you override then in another category. Its safer to override them in a UINavigationController (or UITabBarController) subclass
Also, this does not cover the scenario where you push / present / pop from a Landscape view into a portrait only VC or vice-versa. To solve this tough issue (never addressed by Apple), you should:
In iOS <= 4 and iOS >= 6:
In iOS 5:
These will REALLY force UIKit to re-evaluate all your shouldAutorotate , supportedInterfaceOrientations, etc.
I have a relatively complex universal app using UISplitViewController and UISegmentedController, and have a few views that must be presented in Landscape using
presentViewController
. Using the methods suggested above, I was able to get iPhone ios 5 & 6 to work acceptably, but for some reason the iPad simply refused to present as Landscape. Finally, I found a simple solution (implemented after hours of reading and trial and error) that works for both devices and ios 5 & 6.Step 1) On the controller, specify the required orientation (more or less as noted above)
Step 2) Create a simple UINavigationController subclass and implement the following methods
Step 3) Present your viewController
Hope this is helpful to someone.