-
Re: Support different orientations in controllers embedded in a navigation
Claude31 Nov 28, 2019 7:41 AM (in response to RamiroDiaz)Isn't it:
override open var supportedInterfaceOrientations : UIInterfaceOrientationMask { return .all }
-
Re: Support different orientations in controllers embedded in a navigation
RamiroDiaz Nov 28, 2019 8:24 AM (in response to Claude31)I already tried that. Where are you suggesting to put that? Did you reach any case where navigationControllerSupportedInterfaceOrientations got called?
Thanks
-
Re: Support different orientations in controllers embedded in a navigation
Claude31 Nov 28, 2019 2:26 PM (in response to RamiroDiaz)Did you take care of the _ in the signature of the func before the argument ?
-
Re: Support different orientations in controllers embedded in a navigation
RamiroDiaz Nov 29, 2019 3:53 AM (in response to Claude31)Yes, I did . Thanks for your answer
-
Re: Support different orientations in controllers embedded in a navigation
Claude31 Nov 29, 2019 7:10 AM (in response to RamiroDiaz)OK, please show the code where you call this API.
And if possible show the complete code for the class, the problem may be elsewhere.
-
-
-
-
-
Re: Support different orientations in controllers embedded in a navigation
OOPer Nov 28, 2019 10:59 AM (in response to RamiroDiaz)My problem is that this method never gets called. Any thoughts?
Please clarify which method do you mean by this method. "navigationControllerSupportedInterfaceOrientations" or preferredInterfaceOrientationForPresentation?
Assuming navigationControllerSupportedInterfaceOrientations, you may be mistaking something when implementing the delegate method `navigationControllerSupportedInterfaceOrientations` or setting the delegate of the navigation controller.
I created a simple project with navigation controller and navigationControllerSupportedInterfaceOrientations is called multiple times.
Please show your code.
-
Re: Support different orientations in controllers embedded in a navigation
RamiroDiaz Nov 29, 2019 3:57 AM (in response to OOPer)Yes, i´m talking about navigationControllerSupportedInterfaceOrientations. The delegate is fine, because the other methods are being called.
This is the signature:
func navigationControllerSupportedInterfaceOrientations(_ navigationController: UINavigationController) -> UIInterfaceOrientationMask
I'll try to push an example asap. Given the fact you already tried that, could you share your example with me?
Thank you very much for all your help!
Ramiro
-
Re: Support different orientations in controllers embedded in a navigation
OOPer Nov 29, 2019 6:20 PM (in response to RamiroDiaz)Please show your code first.
-
Re: Support different orientations in controllers embedded in a navigation
Claude31 Nov 30, 2019 1:21 AM (in response to RamiroDiaz)The delegate is fine, because the other methods are being called.
What other delegate method do you call successfully ?
-
-
-
Re: Support different orientations in controllers embedded in a navigation
RamiroDiaz Dec 2, 2019 3:40 AM (in response to RamiroDiaz)I managed to get navigationControllerSupportedInterfaceOrientations called during the start up, but then, when I push a new controller, it´s not called (it seems that if you declare supportedInterfaceOrientations in the navigation controller, the delegate method is not called).
//Initial controller. PortaitViewController is the top view controller in CustomNavigationController. When I push LandscapeViewController, I need the device to rotates automatically to landscape.
class PortaitViewController: UIViewController { @IBAction func landscapeTUI(_ sender: Any) { let vc = LandscapeViewController(nibName: "LandscapeViewController", bundle: nil) self.navigationController?.pushViewController(vc, animated: true) } override var supportedInterfaceOrientations : UIInterfaceOrientationMask { return .portrait } override var shouldAutorotate : Bool { return true } }
class LandscapeViewController: UIViewController { override var supportedInterfaceOrientations : UIInterfaceOrientationMask { return .landscapeLeft } override var shouldAutorotate : Bool { return true }
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { return .landscapeLeft } }
class CustomNavigationController: UINavigationController { override func viewDidLoad() { super.viewDidLoad() self.delegate = self } } extension CustomNavigationController: UINavigationControllerDelegate { func navigationControllerSupportedInterfaceOrientations(_ navigationController: UINavigationController) -> UIInterfaceOrientationMask { return self.topViewController?.supportedInterfaceOrientations ?? .portrait } }
-
Re: Support different orientations in controllers embedded in a navigation
Claude31 Dec 2, 2019 4:09 AM (in response to RamiroDiaz)shouldAutorotate is true
if the content should rotate, otherwisefalse
. This method returnstrue
by default.So, the following is not needed
override var shouldAutorotate : Bool { return true }
Don't you confuse what shouldAutorotate is for ?
It does not force to rotate, it allows to automatically rotate the view when device is turned
have a look here on how to handle the case of a navigationController.
https://stackoverflow.com/questions/27037839/force-landscape-mode-in-one-viewcontroller-using-swift
-
Re: Support different orientations in controllers embedded in a navigation
RamiroDiaz Dec 2, 2019 4:52 AM (in response to Claude31)Hi! Thanks again!
Yes, I understand the purpose of shouldAutorotate.
Don´t you feel like the way tried in that post it´s like a hack? Also I´ve experienced weird animations with that approach.
let value = UIInterfaceOrientation.landscapeLeft.rawValue
UIDevice.current.setValue(value, forKey: "orientation")-
Re: Support different orientations in controllers embedded in a navigation
Claude31 Dec 2, 2019 4:55 AM (in response to RamiroDiaz)Honestly, I did not test.
But I know that you need specific handling of some functions to accomodate the NavigationController that is inserted in the flow of controllers.
So the following did appear to make sense:
// If your view is embedded in a navigation controller the above alone won't work. you have to cascade up // So add the following extension after the class definition extension UINavigationController { override open var shouldAutorotate: Bool { get { if let visibleVC = visibleViewController { return visibleVC.shouldAutorotate } return super.shouldAutorotate } } override open var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation{ get { if let visibleVC = visibleViewController { return visibleVC.preferredInterfaceOrientationForPresentation } return super.preferredInterfaceOrientationForPresentation } } override open var supportedInterfaceOrientations: UIInterfaceOrientationMask{ get { if let visibleVC = visibleViewController { return visibleVC.supportedInterfaceOrientations } return super.supportedInterfaceOrientations } }}
-
Re: Support different orientations in controllers embedded in a navigation
RamiroDiaz Dec 2, 2019 5:17 AM (in response to Claude31)Thanks anyways. The approach mentioned above is essentially what I did, and does not work.
-
Re: Support different orientations in controllers embedded in a navigation
Claude31 Dec 2, 2019 7:16 AM (in response to RamiroDiaz)Last idea. Did you try to set navController and child controllers to full screen presentation instead of automatic ?
-
Re: Support different orientations in controllers embedded in a navigation
RamiroDiaz Dec 2, 2019 6:30 PM (in response to Claude31)I did, but thanks again for your try
-
-
-
-
-
-