Skip to content

Instantly share code, notes, and snippets.

@darkseed
Created July 15, 2011 21:55
Show Gist options
  • Save darkseed/1085628 to your computer and use it in GitHub Desktop.
Save darkseed/1085628 to your computer and use it in GitHub Desktop.
Block based notification
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[nc addObserverForName:UIDeviceOrientationDidChangeNotification object:nil
queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif){
UIDeviceOrientation orientation;
orientation = [[UIDevice currentDevice] orientation];
if (UIDeviceOrientationIsPortrait(orientation)) {
NSLog(@"portrait");
} else {
NSLog(@"landscape");
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment