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.
Swift 3 | UIDeviceOrientationDidChange Notification Observed Too Often
The following code prints "deviceDidRotate" every time your device changes orientation in 3D space - regardless of a change from portrait to landscape orientation. For example, if you hold your phone in portrait orientation and tilt it forward and backward - deviceDidRotate() is called repeatedly.
To work around this you could hold the previous device orientation and check for a change in deviceDidRotate().
Or you can use a different notification that only gets called when the device changes from landscape to portrait. In this case you'd want to use the
UIApplicationDidChangeStatusBarOrientation
notification.Use the new viewWillTransitionToSize(_:withTransitionCoordinator:)
Easy, this works in iOS8 and 9 / Swift 2 / Xcode7, just put this code inside your viewcontroller.swift. It will print the screen dimensions with every orientation change, you can put your own code instead:
In Objective C
In swift
Override this method to detect the orientation change.
Since iOS 8 this is the correct way to do it.
I like checking the orientation notification because you can add this feature in any class, no needs to be a view or a view controller. Even in your app delegate.
than caching the notification