Code Monkey home page Code Monkey logo

Comments (8)

arhangelskij avatar arhangelskij commented on July 17, 2024 5

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")
    }

from skphotobrowser.

krummler avatar krummler commented on July 17, 2024 1

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

from skphotobrowser.

nicol3a avatar nicol3a commented on July 17, 2024 1

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

from skphotobrowser.

doseAt avatar doseAt commented on July 17, 2024

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

from skphotobrowser.

maziyarpanahi avatar maziyarpanahi commented on July 17, 2024

@arhangelskij worked like a charm! thanks mate!

from skphotobrowser.

tarigancana avatar tarigancana commented on July 17, 2024

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

from skphotobrowser.

maziyarpanahi avatar maziyarpanahi commented on July 17, 2024

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

from skphotobrowser.

onursahindur avatar onursahindur commented on July 17, 2024

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.

from skphotobrowser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.