Skip to content

Instantly share code, notes, and snippets.

@stephenkeep
Created March 11, 2013 11:48
Show Gist options
  • Save stephenkeep/5133691 to your computer and use it in GitHub Desktop.
Save stephenkeep/5133691 to your computer and use it in GitHub Desktop.
Device Orientation Notification
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object: nil];
}
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
#pragma mark Rotation Methods
- (void)orientationChanged:(NSNotification *)notification
{
[self performSelector:@selector(showScreen) withObject:nil afterDelay:0];
}
-(void)showScreen {
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
if (deviceOrientation == UIDeviceOrientationLandscapeLeft || deviceOrientation == UIDeviceOrientationLandscapeRight) {
NSLog(@"changed landscape");
} else {
NSLog(@"changed portrait");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment