SKPhotoBrowser icon indicating copy to clipboard operation
SKPhotoBrowser copied to clipboard

different supportedInterfaceOrientations for SKPhotoBrowser

Open maziyarpanahi opened this issue 8 years ago • 8 comments

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,

maziyarpanahi avatar May 06 '16 17:05 maziyarpanahi

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 :).

krummler avatar May 14 '16 18:05 krummler

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! :)

nicol3a avatar Aug 31 '16 10:08 nicol3a

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 avatar Jan 20 '17 11:01 arhangelskij

@arhangelskij that's the solution, from begining to end, thanks!

doseAt avatar Mar 01 '17 11:03 doseAt

@arhangelskij worked like a charm! thanks mate!

maziyarpanahi avatar Mar 05 '17 14:03 maziyarpanahi

Hi, seems the solution by @arhangelskij not work for me :(

tarigancana avatar Dec 01 '17 06:12 tarigancana

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

maziyarpanahi avatar Dec 14 '17 22:12 maziyarpanahi

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.

onursahindur avatar Jan 28 '23 10:01 onursahindur