jen*_*nen 41 landscape orientation ios6
我的应用程序仅通过supportedInterfaceOrientation属性支持横向方向.
使用iOS 6之前的iOS,我的应用程序可以成功加载UIImagePickerControllervia 的实例,presentViewController:animated:completion:即使它UIImagePickerController本身只支持纵向方向.
图像选择器简单地向用户侧面呈现.用户旋转手机,拾取他们的图像,然后旋转回横向.
在iOS 6.0下,presentViewController:animated:completion:使用UIImagePickerController实例调用会使应用程序崩溃.我可以通过向我的supportedInterfaceOrientation属性添加纵向选项来防止崩溃.
但是,纵向操作对我的应用来说真的没有用.我原本以为我可以使用shouldAutorotateToInterfaceOrientation该应用程序"支持肖像",但只允许在这一个视图中旋转到肖像.但是现在该方法已被弃用,我不能在shouldAutorotate中使用相同的技术.
有没有人有任何想法如何在iOS 6.0下解决这个问题?
Dan*_*iel 80
从iOS 6.1开始,这不再发生,为了避免iOS 6.0.x下的崩溃,遵循我的提示是非常重要的,下面仍然适用于此.
这实际上是iOS 6.0中的一个错误,这应该在未来的iOS版本中修复.
Apple的一位工程师在这里解释了这个错误和解决方法:https://devforums.apple.com/message/731764
这种情况正在发生,因为应用程序只需要横向方向,但是一些Cocoa Touch视图控制器需要严格的纵向方向,这是错误 - 不是它们应该需要更多的肖像,而是它们对应用程序要求的解释.
这方面的一个例子如下:
支持横向的iPad应用程序仅通过UIPopoverController显示UIImagePickerController.UIImagePickerController需要纵向方向,但应用程序仅强制横向显示.错误和...崩溃
报告为有问题的其他框架包括Game Center登录视图控制器.
解决方法非常简单但不理想......您保持在info.plist /项目信息窗格中声明的正确方向,但在Application Delegate类中,您声明允许所有方向.
现在,您添加到窗口的每个View Controller必须指定它只能是Landscape.请查看链接以获取更多详细信息.
我不能强调你不应该做多少子类化,UIImagePickerController因为公认的解决方案坚持你这样做.

这里重要的是" 此类旨在按原样使用,并且不支持子类化."
在我的情况下,我将此添加到我的应用程序的委托(我有一个仅景观应用程序),这告诉它可以显示的图像选择器,因为支持肖像:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskAll;
}
Run Code Online (Sandbox Code Playgroud)
然后在我的视图控制器中碰巧是一个UINavigationController,我包含了一个类别如下:
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
Run Code Online (Sandbox Code Playgroud)
现在我的应用程序没有旋转,图像选择器询问代表是否可以显示为肖像,并且它被告知没关系.所以一切都很顺利.
ecl*_*lux 41
我有类似的问题,但在iPad横向应用程序中.我在弹出窗口中呈现图像选择器.它在iOS 6下崩溃.错误表明选择器想要肖像,但应用程序只提供横向视图,并且......重要的是...选择器的shouldRotate返回YES.
我将此添加到我正在创建选择器的ViewControllerClass.m中
@interface NonRotatingUIImagePickerController : UIImagePickerController
@end
@implementation NonRotatingUIImagePickerController
- (BOOL)shouldAutorotate
{
return NO;
}
@end
Run Code Online (Sandbox Code Playgroud)
然后使用该类代替
UIImagePickerController *imagePicker = [[NonRotatingUIImagePickerController alloc] init];
[myPopoverController setContentViewController:imagePicker animated:YES];
Run Code Online (Sandbox Code Playgroud)
这解决了我的问题.你的情况有点不同,但听起来基本上是同样的错误.
Jon*_*iel 26
虽然子类化UIImagePickerController有效,但类别是更好的解决方案:
@implementation UIImagePickerController (NonRotating)
- (BOOL)shouldAutorotate
{
return NO;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
@end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20670 次 |
| 最近记录: |