I am using Swift and I want to be able to load a UIViewController when I rotate to landscape, can anyone point me in the right direction?
I Can't find anything online and a little bit confused by the documentation.
I am using Swift and I want to be able to load a UIViewController when I rotate to landscape, can anyone point me in the right direction?
I Can't find anything online and a little bit confused by the documentation.
If you want to do something AFTER the rotation is complete, you can use the
UIViewControllerTransitionCoordinator
completion handler like thisHere is an easy way to detect the device orientation: (Swift 3)
My approach is similar to what bpedit shows above, but with an iOS 9+ focus. I wanted to change the scope of the FSCalendar when the view rotates.
This below worked, but I felt sheepish about it :)
Check if rotation had changed with:
viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator)
With the
coordinator.animateAlongsideTransition(nil) { (UIViewControllerTransitionCoordinatorContext)
you can check if the transition is finished.See code below:
Here's how I got it working:
In
AppDelegate.swift
inside thedidFinishLaunchingWithOptions
function I put:and then inside the AppDelegate class I put the following function:
Hope this helps anyone else!
Thanks!