I want to catch the event in a UIViewcontroller when the device orientations changes and change the view content accordingly. However, the funcs doing this seems to be deprecated. How to solve this?
Asked
Active
Viewed 488 times
1 Answers
1
In AppDelegate.swift inside the "didFinishLaunchingWithOptions" function put:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "rotated", name: UIDeviceOrientationDidChangeNotification, object: nil)
and then inside the AppDelegate class put the following function:
func rotated()
{
if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation))
{
println("landscape")
}
if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation))
{
println("Portrait")
}
}

SwiftStudier
- 2,272
- 5
- 21
- 43
-
I want to catch the orientation change in the viewcontroller. I don't understand how to catch this event with the example above. – JonP Sep 16 '15 at 05:20
-
If you don't have your AppDelegate set up, you can put the `NotificationCenter...` line in your View Controller's viewDidLoad and add the `func rotated()` as an additional function for your View Controller – GlennRay Jan 30 '16 at 03:34