A
A
Alexander2017-11-15 14:10:44
Objective-C
Alexander, 2017-11-15 14:10:44

How to turn off rotation for one controller?

Given: two controllers, main and child. The main should always maintain portrait orientation, and the child should rotate when the phone is rotated. Also, the child controller must be translucent.
FirstViewController.swift

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .portrait
}
override var shouldAutorotate: Bool {
    return false
}

SecondViewController.swift
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .allButUpsideDown
}
override var shouldAutorotate: Bool {
    return true
}

Opening a child controller:
let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as! SecondViewController
secondViewController.modalPresentationStyle = .custom
self.present(secondViewController, animated: true, completion: nil)

The problem is that when you open the child controller and when you rotate the screen, the main controller also rotates.
Test project: https://github.com/sieroshtan/RotationTest

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Guzenko, 2017-11-24
@InViZz

try to implement the preferredInterfaceOrientationForPresentation method for the first controller and return .portrait from there, it used to work))

func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
        return .portrait
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question