GSImageViewerController icon indicating copy to clipboard operation
GSImageViewerController copied to clipboard

How to open GSImageViewerController in landscape mode (depending on current orientation).

Open RakeshKoplodR opened this issue 4 years ago • 2 comments
trafficstars

I would like to open an image depending on the device's current orientation. For example if device is in landscape mode image should rotate. Now it is showing in portrait mode only and not rotating in landscape mode.

RakeshKoplodR avatar Jun 02 '21 12:06 RakeshKoplodR

You can inherit GSImageViewerController and try to modify it.

see https://github.com/wxxsw/GSImageViewerController/issues/28

wxxsw avatar Jun 03 '21 08:06 wxxsw

Late in the party! I'm still happy to help you guys.

Use supportedInterfaceOrientationsFor application delegate and add the following code in the AppDelegate file.

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    if isLandscape {
        return UIInterfaceOrientationMask.all
    }else{
        return UIInterfaceOrientationMask.portrait
    }
}

Add this line to your GSImageViewerController file

override func viewDidLoad() {
    super.viewDidLoad()
    isLandscape = true
}

override func viewWillDisappear(_ animated: Bool) {
    isLandscape = false
}

And don't forget to add a global variable in the app delegate file

var isLandscape = false

Also, I suggest adding 'GSImageViewerController.swift' to your project instead of using a pod file to avoid file override issues in the future while a pod updates.

krunal545 avatar Dec 19 '23 13:12 krunal545