Skip to content

Instantly share code, notes, and snippets.

@ChrisRisner
Created November 21, 2012 04:57
Show Gist options
  • Save ChrisRisner/4123116 to your computer and use it in GitHub Desktop.
Save ChrisRisner/4123116 to your computer and use it in GitHub Desktop.
iOS Day 16
-(BOOL) shouldAutorotate {
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortrait;
}
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *lblInfo;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(@"Landscape left");
self.lblInfo.text = @"Landscape left";
} else if (orientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"Landscape right");
self.lblInfo.text = @"Landscape right";
} else if (orientation == UIInterfaceOrientationPortrait) {
NSLog(@"Portrait");
self.lblInfo.text = @"Portrait";
} else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
NSLog(@"Upside down");
self.lblInfo.text = @"Upside down";
}
}
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(@"Landscape left");
self.lblInfo.text = @"Landscape left";
} else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"Landscape right");
self.lblInfo.text = @"Landscape right";
} else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
NSLog(@"Portrait");
self.lblInfo.text = @"Portrait";
} else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
NSLog(@"Upside down");
self.lblInfo.text = @"Upside down";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment