0

我想保持我的视野。为此,我正在使用此代码,但 BAD_ACCESS 即将到来。在这里,我正在为相机叠加视图编写此代码。

 -(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 ?

4

1 回答 1

4

要保持您的视图横向,只需返回纵向方向NOshouldAutorotateToInterfaceOrientation:方法,例如 tihs :

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
于 2012-04-10T11:36:55.643 回答