簡體   English   中英

橫向時 BAD_ACCESS

[英]BAD_ACCESS while landscape orientation

我想保留我的風景。 為此,我正在使用此代碼,但 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?

為了讓你的視圖保持橫向,只需在你的shouldAutorotateToInterfaceOrientation:縱向方法中返回NO ,比如 tihs:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM