Created
March 11, 2013 11:48
-
-
Save stephenkeep/5133691 to your computer and use it in GitHub Desktop.
Device Orientation Notification
This file contains 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
- (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