Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to present a landscape only ViewController from portrait bottom of iPhone in swift?

I have portrait only app with one screen in landscape only mode.

What I did: I created a UINavigationController subclass and overridden the following:

import UIKit

class LandscapeVCNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .landscape
    }
    override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
        return .landscapeLeft
    }
}

Then using this navigationController to present my landscape viewcontroller like this:

if let vc = storyboard?.instantiateViewController(withIdentifier: StoryBoardIdentifiers.playerVCStoryboardIdentifier) as? PlayerViewController {

            let navController = LandscapeVCNavigationController.init(rootViewController: vc)

            present(navController, animated: true, completion: {
            })
        }

This works fine.

What I need:

I need the landscape VC to be presented from the bottom(home button side) and should dismiss to the bottom(home button side). This is what happens currently.

enter image description here

like image 957
abhimuralidharan Avatar asked Nov 08 '22 20:11

abhimuralidharan


1 Answers

You have to add a custom transition animation to change this default behaviour.

    let transition = CATransition()
    transition.duration = 0.3
    transition.timingFunction = CAMediaTimingFunction(name:kCAMediaTimingFunctionEaseInEaseOut)
    transition.type = kCATransitionPush
    transition.subtype = kCATransitionFromLeft
    self.view!.window!.layer.add(transition, forKey: nil)
    self.present(navController, animated: false, completion:nil) 
like image 170
Harikrishnan R Avatar answered Nov 14 '22 22:11

Harikrishnan R