横向方向时BAD_ACCESS

时间:2012-04-10 11:21:11

标签: iphone ios ipad

我希望保持自己的视野。为此,我使用此代码,但BAD_ACCESS即将到来。 在这里,我正在为相机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];
 } 

为什么要给予BAD ACCESS?

1 个答案:

答案 0 :(得分:4)

要保持您的观看格局,只需在NO方法中返回shouldAutorotateToInterfaceOrientation:纵向方向,例如:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}