0

I want to keep my view landscape. For that i am using this code but BAD_ACCESS is coming. Here I am writing this code for camera overlayView.

 -(void)viewDidLoad
 {
     [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];
     //Set Notifications so that when user rotates phone, the orientation is reset to landscape.
     [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
     //Refer to the method didRotate:   
     [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(didRotate:)
              name:@"UIDeviceOrientationDidChangeNotification" object:nil];
     [super viewDidLoad];
 }

 - (void) didRotate:(NSNotification *)notification
 {
        //Maintain the camera in Landscape orientation
        [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];
 } 

Why it is giving BAD ACCESS ?

Lucifer
  • 29,392
  • 25
  • 90
  • 143
komal mehta
  • 269
  • 5
  • 14
  • `orientation` property is read-only. How you are setting up it? It should give a warning. – beryllium Apr 10 '12 at 11:29
  • 1
    Just as an aside - it's bad practice to use the value `@"UIDeviceOrientationDidChangeNotification"` if the constant `UIDeviceOrientationDidChangeNotification` exists, you should always use the constant. It lets the compiler tell you if you've misspelled it and what if the value changes in future versions of iOS? (Agreed, unlikely in this case but it's always better to be sure!) – deanWombourne Apr 10 '12 at 11:40

1 Answers1

4

To keep your view landscape, just return NO in your shouldAutorotateToInterfaceOrientation: method for portrait orientations, like tihs :

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
deanWombourne
  • 38,189
  • 13
  • 98
  • 110