SKPhotoBrowser
SKPhotoBrowser copied to clipboard
different supportedInterfaceOrientations for SKPhotoBrowser
Hi,
This is not an issue just a quick question. Is there a way to have the entire project in Portrait and only detect if SKPhotoBrowser is the view and change it to UIInterfaceOrientationMask.All? Something like this:
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
super.supportedInterfaceOrientations()
if presentedViewController?.isKindOfClass(SKPhotoBrowser) != nil {
return UIInterfaceOrientationMask.All
} else {
return UIInterfaceOrientationMask.Portrait
}
}
Unfortunately this doesn't work.
This is my info.plist:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
Many thanks,
I'm not entirely sure, but if you limit your app to one orientation, you can't really make an exception.
I would go at it the other way around:
- Allow all directions
- Make a subclass of UIViewController, where you limit the orientation to Portrait.
- Make sure all of your ViewControllers subclass your newly created VC
- Since the SKProtoBrowser doesn't subclass from your VC, it won't be limited to portrait.
Do you know what I mean? Please let me know if this helps out :).
I just had the same issue, I have an iPhone app which is in portrait only, and I wanted to have the SKPhotoBrowser to support all orientations.
The problem is, since SKPhotoBrowser is using a custom modal presentation style, the rotation doesn't work in the SKPhotoBrowser if the view controller presenting the SKPhotoBrowser doesn't support several interface orientations.
Even if you add shouldAutorotate
and supportedInterfaceOrientations
methods in the SKPhotoBrowser class.
The solution is to change the modal presentation style by using the fullscreen mode. Then it works, but the downside is that you will not have the background fading away as you're dismissing the photo (the transparent background is only accessible if you're using CurrentContext, OverFullscreen or Custom modal presentation style).
Hope it helps! :)
Hi guys. I have solution. It's tested in my project for iOS 10.x
In AppDelegate add variable
var restrictRotation: Bool = true
and method
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if restrictRotation {
return UIInterfaceOrientationMask.portrait
}
return UIInterfaceOrientationMask.all
}
Then when you tap on your image you have to implement next
func restrictRotation(_ restriction:Bool) {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.restrictRotation = restriction
}
func tapYourImage () {
restrictRotation(false)
}
Then when you finish to view pictures implement method willDismissAtPageIndex of SKPhotoBrowserDelegate
func willDismissAtPageIndex(_ index: Int) {
restrictRotation(true)
let value = NSNumber(value:UIInterfaceOrientation.portrait.rawValue)
UIDevice.current.setValue(value, forKey: "orientation")
}
@arhangelskij that's the solution, from begining to end, thanks!
@arhangelskij worked like a charm! thanks mate!
Hi, seems the solution by @arhangelskij not work for me :(
I have another problem with this solution. If you slowly drag the photo down/up to dismiss you can see the view under the photo is landscape until willDismissAtPageIndex
is called and it changes it to portrait.
Is this the same for you as well? @arhangelskij
If there was only a delegate for willVerticalSwipeStart
to catch this as quick as possible.
many thanks
Since this issue is still open; If anyone is looking for a solution to lock the orientation, you can extend SKPhotoBrowser as follows and lock the orientation.
extension SKPhotoBrowser {
open override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
}
Happy coding.