【发布时间】:2013-09-30 06:17:23
【问题描述】:
我在 UIPopoverController 中使用 UIImagePickerController,它与 iOS6 完美配合。在 iOS 7 中,为了捕捉图像而显示的“预览”图像会旋转,但如果我拍照,它会被正确保存。
这就是我获得选择器的方式:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
并将其添加到弹出框控制器:
self.imagePickerPopOver = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[self.imagePickerPopOver presentPopoverFromRect:CGRectMake(aPosViewA.x, cameraButton_y, 100.0, 30.0) inView:self.detailViewController.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
这些是 UIScrollView 上按钮位置的计算,以在正确的位置显示弹出框:
presentPopoverFromRect:CGRectMake(aPosViewA.x, cameraButton_y, 100.0, 30.0)
我认为问题不在于那里,因为我已经尝试了几种组合。
我也尝试在全屏模式下捕捉图像,但该应用只允许使用横向模式。如果图像是在纵向模式下拍摄的并且模态视图被关闭,则应用程序也会保持纵向模式。如果模式视图被关闭,我找不到阻止 UIImagePickerController 切换到纵向模式或强制应用返回横向模式的方法。
更新
我已经从here那里得到了答案,并且更进一步。
我在创建选择器之后和显示弹出框之前转换视图:
switch ([UIApplication sharedApplication].statusBarOrientation) {
case UIInterfaceOrientationLandscapeLeft:
self.imagePicker.view.transform = CGAffineTransformMakeRotation(M_PI/2);
break;
case UIInterfaceOrientationLandscapeRight:
self.imagePicker.view.transform = CGAffineTransformMakeRotation(-M_PI/2);
break;
default:
break;
}
只要我不转动 iPad,它就可以工作。为此,我正在注册方向更改事件:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
并更改选择器视图:
- (void)orientationChanged:(NSNotification *)notification{
if (self.imagePicker) {
switch ([UIApplication sharedApplication].statusBarOrientation) {
case UIInterfaceOrientationLandscapeLeft:
self.imagePicker.view.transform = CGAffineTransformMakeRotation(M_PI/2);
break;
case UIInterfaceOrientationLandscapeRight:
self.imagePicker.view.transform = CGAffineTransformMakeRotation(-M_PI/2);
break;
default:
break;
}
}
}
剩下的问题: 正如我在开始时所写的那样,当照片被拍摄时,它被正确地显示为接受或拒绝它。现在也进行了改造。不知何故,我需要知道何时拍摄图像并将其转换回来。
而且,这确实是一个令人讨厌的 hack,并且可能不适用于下一个 iOS 更新。有人知道如何以更清洁的方式实现它吗?
更新 2
这太讨厌了,我找到了一个更干净的解决方案,可以解决我的问题,但不是关于弹出框控制器中图像选择器的初始问题的答案,Apple 不推荐,但允许这样做。
我现在已经像这样子类化 UIImagePickerController:
@implementation QPImagePickerController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
@end
我正在全屏使用图像选择器,而不是在弹出窗口中。目前在 iOS7 中测试。
【问题讨论】:
-
我面临着完全相同的问题。我不敢相信这不是一个更相关的问题——它怎么不破坏更多的应用程序?
-
一模一样的问题,下次更新不会解决吗?
-
在我看来,同样的问题正在影响使用弹出式摄像头的 ios7 facebook 应用程序。
-
在 iOS7 iPad 环境中只有应用程序我得到'UIApplicationInvalidInterfaceOrientation',原因:'支持的方向与应用程序没有共同的方向,并且 shouldAutorotate 正在返回 YES'
标签: ios uiimagepickercontroller ios7 uipopovercontroller uiinterfaceorientation