I am trying to rotate one view while all other views (5) are fixed to portrait. The reason is that in that one view I want the user to watch pictures which he saved before. I guess this is possible but so far I couldn't figure out how to achieve that. Can anyone help or give me a hint? I am programming that in Swift running on iOS8
相关问题
- 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
- SwiftUI: UIImage (QRCode) does not load after call
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- 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
Use the
shouldAutorotate
and thesupportedInterfaceOrientations
method in the ViewController you want to display in landscape and portrait mode:This method should override the storyboard-settings.
You can also do it in a protocol oriented way. Just create the protocol
Add the the same 2 methods in the AppDelegate in a more "swifty" way
And in every ViewController that you want a different behaviour, just add the protocol name in the definition of the class.
If you want any particular combination, they you can add to the protocol a variable to override
This is for Swift 3 and Swift 4. You can use the follow code in your AppDelegate.swift :
you can learn more in the original post: http://www.jairobjunior.com/blog/2016/03/05/how-to-rotate-only-one-view-controller-to-landscape-in-ios-slash-swift/
I'd recommend using
supportedInterfaceOrientationsForWindow
in yourappDelegate
to allow rotation only in that specific view controller, ex:Swift 3 <
Note that if that SpecificViewController is in landscape before going to a portrait screen, the other view will still open in landscape. To circumvent this, I'd recommend disallowing transitions while that view is in landscape.
Swift 4
Sometimes when you're using a custom navigation flow (that may get really complex) the above-mentioned solutions may not always work. Besides, if you have several ViewControllers that need support for multiple orientations it may get quite tedious.
Here's a rather quick solution I found. Define a class
OrientationManager
and use it to update supported orientations in AppDelegate:Then in AppDelegate put the orientations you want for that specific case:
Then in the ViewControllers that you want to have multiple navigations update the
OrientationManager
:Also, don't forget to update it once again when you'll be exiting this ViewController:
Hope this helps!
SWIFT 4
For
UITabBarController
can we use this line of code inAppDelegate.swift
.