2012-04-10 18 views
0

私の視野を維持したい。私はこのコードを使用していますが、BAD_ACCESSは来ています。 ここでは、カメラオーバーレイビューのこのコードを書いています。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を提供していますか?

+0

'orientation'プロパティは読み取り専用です。どのように設定していますか?それは警告を与えるべきです。 – beryllium

+1

定数 'UIDeviceOrientationDidChangeNotification'が存在する場合は、値' @ "UIDeviceOrientationDidChangeNotification"を使用するのは悪い習慣です。常に定数を使用する必要があります。コンパイラは、スペルミスを訂正したかどうか、およびiOSの将来のバージョンで値が変更された場合はどうすればいいのかを教えてくれますか? (合意、この場合はありそうもありませんが、必ず確実にしてください!) – deanWombourne

答えて

4

だけtihsように、縦長の向きのためのあなたのshouldAutorotateToInterfaceOrientation:方法でNOを返し、ビューの景観を保つために:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
} 
関連する問題