Created
August 23, 2014 12:55
-
-
Save genedelisa/9a5ac67c73b1517e9fe3 to your computer and use it in GitHub Desktop.
Receive device orientation notifications in Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool { | |
// Override point for customization after application launch. | |
UIDevice.currentDevice().beginGeneratingDeviceOrientationNotifications() | |
NSNotificationCenter.defaultCenter().addObserver(self, | |
selector: "detectOrientation", | |
name:UIDeviceOrientationDidChangeNotification, | |
object:nil) | |
return true | |
} | |
func detectOrientation() { | |
switch UIDevice.currentDevice().orientation { | |
case UIDeviceOrientation.Unknown: | |
println("Unknown") | |
case UIDeviceOrientation.Portrait: | |
println("Portrait") | |
case UIDeviceOrientation.PortraitUpsideDown: | |
println("PortraitUpsideDown") | |
case UIDeviceOrientation.LandscapeLeft: | |
println("LandscapeLeft") | |
case UIDeviceOrientation.LandscapeRight: | |
println("LandscapeRight") | |
case UIDeviceOrientation.FaceUp: | |
println("FaceUp") | |
case UIDeviceOrientation.FaceDown: | |
println("FaceDown") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment