BAD_ACCESS虽然风景取向
问题描述:
我想保持我的风景。为此,我使用此代码,但BAD_ACCESS即将到来。 在这里,我正在为摄像机overlayView编写此代码。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?
答
为了让您的观点的景观,只是在你的shouldAutorotateToInterfaceOrientation:
方法返回NO
为纵向模式,就像tihs:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
'orientation'属性为只读。你如何设置它?它应该给出警告。 – beryllium 2012-04-10 11:29:37
就像旁边一样 - 如果常量“UIDeviceOrientationDidChangeNotification”存在,则使用值“@”UIDeviceOrientationDidChangeNotification“'是不好的做法,您应该始终使用该常量。它可以让编译器告诉你,你是否拼错了它,以及如果在未来版本的iOS中值发生变化会怎样? (同意,不太可能在这种情况下,但总是肯定会更好!) – deanWombourne 2012-04-10 11:40:56