Skip to content

Instantly share code, notes, and snippets.

@genedelisa
Created August 23, 2014 12:55
Show Gist options
  • Save genedelisa/9a5ac67c73b1517e9fe3 to your computer and use it in GitHub Desktop.
Save genedelisa/9a5ac67c73b1517e9fe3 to your computer and use it in GitHub Desktop.
Receive device orientation notifications in Swift
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