vir*_*wal 15 iphone cocoa-touch objective-c ios5 ios6
*我的观点是在陆地景观模式我正在保存图像,我希望该图像回来,我的代码在下面,我发现错误"终止应用程序由于未捕获的异常'UIApplicationInvalidInterfaceOrientation',原因:'支持的方向没有共同的方向与应用程序,并且shouldAutorotate返回YES'"*我能为iPhone做什么?
`- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissModalViewControllerAnimated:YES];
[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:NO];
imageDoodle.image = [info objectForKey:@"UIImagePickerControllerMediaMetadata"];
}
-(IBAction)loadfromalbumclicked:(id)sender
{
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing=NO;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
// self.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:picker animated:YES];
}
-(IBAction)savePrint{
//Save image to iOS Photo Library
UIImageWriteToSavedPhotosAlbum(imageDoodle.image, nil, nil, nil);
//Create message to explain image is saved to Photos app library
UIAlertView *savedAlert = [[UIAlertView alloc] initWithTitle:@"Saved"
message:@"Your picture has been saved to the photo library, view it in the
Photos app." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
//Display message alert
[savedAlert show];
}`
Run Code Online (Sandbox Code Playgroud)
vsh*_*all 16
尝试将shouldAutoRotate设置为NO,看看它是否有效.
您可以在iOS 6.0或更高版本中使用shouldAutoRotate和supportedInterfaceOrientations方法,而不是(不推荐使用)shouldAutoRotateToInterfaceOrientation方法.
像这样的东西 -
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
- (BOOL) shouldAutorotate {
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
Run Code Online (Sandbox Code Playgroud)
您只支持有限的方向横向或纵向.但是你在视图控制器中调用了不同的方向.
您可以使用支持的方向查看以下图像.它只支持横向右侧和左侧景观.所以,如果我调用肖像,它将像您一样显示错误.因此,如果您想支持两种方向,请在摘要中更改它.

有关详细信息,请参阅此答案. 希望能帮助到你.
编辑
所以你必须把这个代码放在你的viewcontroller中
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
Run Code Online (Sandbox Code Playgroud)
如果plist中支持的接口方向与返回的接口方向不匹配,则会引发此错误 -(NSUInteger)supportedInterfaceOrientations
请记住,该NSUInteger返回的supportedInterfaceOrientations必须是UIInterfaceOrientationMask,注意-MASK-,我曾经做的只是返回UIInterfaceOrientation异的...面膜值的错误(这是自动完成你)
例如
- (NSUInteger) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
// and NOT UIInterfaceOrientationPortrait;
}
Run Code Online (Sandbox Code Playgroud)