【问题标题】:iOS UIImagePickerController freezes when openediOS UIImagePickerController 在打开时冻结
【发布时间】:2012-10-15 05:39:03
【问题描述】:

我目前正在开发一个在 iOS 6 中运行的 iPad 应用

我在我的应用中实现了 UIImagePickerController 的一个子类,它通过覆盖 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 函数来强制相机处于横向。

在通过presentViewController 启动图像选择器时似乎有一个随机的机会,它会在相机“加载”屏幕上被捕获。那个看起来像一个关闭的相机快门。除非您退出或锁定/解锁屏幕,否则应用程序将在此屏幕上冻结,之后它将正常运行。

我还有一个用于相机视图的自定义 UI。但是我在添加之前就注意到了这个问题,所以我认为它是无关的。

这是我必须打开选择器的内容:

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
    self.modalController = [[CameraLandscapeImagePicker alloc] init];
    self.modalController.delegate = self;
    self.modalController.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.modalController.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil];
    self.modalController.allowsEditing = NO;
    [self.viewController presentViewController:modalController animated:YES completion:nil];

    //add the overlaying view ui
    [self.modalController buildCustomOverlay];

    self.newMedia = YES;
}

感谢任何帮助。

[编辑] - 更新: 我已经设法弄清楚如何故意复制这个问题。以下是步骤:

  • 点按我的应用“捕获”按钮以加载相机
  • 退出相机界面
  • 按 ipad 上的主页按钮
  • 点击主屏幕上的图标再次打开应用
  • 再次点按我的应用“捕获”按钮
  • 相机卡在快门屏幕上

我还注意到即使连接到 xcode 也会发生这种情况。

我已经修改了我的代码,以便通过单例提供 UIImagePickerController 对象。以前我每次都创建一个新的 UIImagePickerController 对象。这没有任何影响,我仍然遇到同样的问题。 我已经让应用程序在快门屏幕上运行了大约 5 分钟,但它仍然卡住了。

【问题讨论】:

    标签: ios ipad uiimagepickercontroller freeze


    【解决方案1】:

    我终于知道问题出在哪里了。

    在我添加为 cameraOverlayViewUIImagePicker 的自定义 UI 视图中,我有一个自定义 NavigationBar 视图。 该视图的委托设置为 UIImagePicker,委托属性使用 retain

    最后只是一个词从“保留”更改为“分配”来解决它:

    @property (nonatomic,assign) id delegate;

    如果您遇到与此类似的问题,我建议您将自定义 ui 代码的部分注释掉,以查看究竟是什么导致了问题。

    【讨论】:

      【解决方案2】:

      我遇到了这个问题,并且委托的属性已经很弱(也尝试使用分配),但问题仍然存在。

      我发现我的问题是像这样直接分配UIImagePickerControllercameraOverlayView

      self.picker.cameraOverlayView = self.overlay;
      

      将其更改为以下工作

      [self.picker.cameraOverlayView addSubview:self.overlay];
      

      我在 Apple 示例应用中找到了解决方案:

      http://developer.apple.com/library/ios/#samplecode/PhotoPicker/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010196-Intro-DontLinkElementID_2

      EDIT经过进一步测试,我发现这实际上是不够的。

      正如这篇文章所建议的: Displaying UIImagePickerController within another UIView

      我添加了以下内容以使快门动画“打开”:

      [self.picker viewWillAppear:YES];
      [self presentViewController:self.picker animated:NO completion:nil];
      [self.picker viewDidAppear:YES];
      

      【讨论】:

        猜你喜欢
        • 2017-02-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多