我有一些适用于iPhone 5的代码,但不适用于iPhone 5S或iPad Air。我知道iPhone 5是32位的,其他设备是64位的,但是我看不到这将如何引起我的问​​题。我在选项卡栏上使用带有按钮的相机覆盖层来捕获图片。

我可以像这样实例化UIImagePickerController:

    UIImagePickerController *pick = [[UIImagePickerController alloc] init];
    pick.modalPresentationStyle = UIModalPresentationCurrentContext;
    pick.sourceType = UIImagePickerControllerSourceTypeCamera;
    pick.delegate = self;
    pick.wantsFullScreenLayout=YES;

    /*
     The user wants to use the camera interface. Set up our custom overlay view for the camera.
     */
    CGSize screenBounds = [UIScreen mainScreen].bounds.size;
    CGFloat cameraAspectRatio = 4.0f/3.0f;

    CGFloat camViewHeight = screenBounds.width * cameraAspectRatio;
    CGFloat scale = screenBounds.height / camViewHeight;
    pick.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenBounds.height - camViewHeight) / 2.0);
    pick.cameraViewTransform = CGAffineTransformScale(pick.cameraViewTransform, scale, scale);
    pick.showsCameraControls = NO;

    /*
     Load the overlay view from the OverlayView nib file. Self is the File's Owner for the nib file, so the overlayView outlet is set to the main view in the nib. Pass that view to the image picker controller to use as its overlay view, and set self's reference to the view to nil.
     */
    [[NSBundle mainBundle] loadNibNamed:IS_IPAD ? @"OverlayView-ipad" : @"OverlayView" owner:self options:nil];
    self.overlayView.frame = pick.cameraOverlayView.frame;
    self.focusRect.layer.borderColor = [UIColor colorWithRed:255 green:0 blue:0 alpha:1.0].CGColor;
    pick.cameraOverlayView = self.overlayView;
    self.overlayView = nil;

    self.imagePickerController = pick;
    [self presentViewController:self.imagePickerController animated:YES completion:nil];

focusRect是视图上的红色矩形,用于向用户展示如何居中放置照片。

我已将协议添加到我的.h文件中:UIImagePickerControllerDelegate,UINavigationControllerDelegate

我用IBAction调用takePicture。以下内容适用于32位而非64位:
- (IBAction)takePicture:(id)sender{
    [self.imagePickerController takePicture];
    [self dismissViewControllerAnimated:YES completion:NULL];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    UIImage *chosenImage = info[UIImagePickerControllerOriginalImage]; //64 bit never gets here
    //Do some stuff.
}

症状仅仅是,FinishPickingMediaWithInfo和imagePickerControllerDidCancel都不会在64位设备上执行。我的叠加层被关闭了,但是这些方法中的代码仅在32位设备上执行。

我检查了其他几个问题和答案,例如this。来自不同线程的一些建议是,确保将委托设置为self,向视图添加适当的协议,并确保正确键入方法名称。我相信这些都涵盖了。

我已确认该应用程序以32位运行。由于依赖关系,我将有效架构设置为不带arm64的“arm7 arm7s”。我正在使用XCode5。我将为您提供任何帮助。谢谢您的光临。

最佳答案

看起来这实际上与设备的位数无关,而是它们如何不同地处理ARC。

我通过将dismissViewControllerAnimated从takePicture移到didFinishPickingMediaWithInfo例程中来解决了该问题,如下所示:

- (IBAction)takePicture:(id)sender{
    [self.imagePickerController takePicture];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    UIImage *chosenImage = info[UIImagePickerControllerOriginalImage]; //64 bit never gets here
    //Do some stuff.
    [self dismissViewControllerAnimated:YES completion:NULL];
}

我的理论是对象可以在调用委托方法之前被销毁。

09-10 04:28
查看更多