4

我有一个几乎完成的应用程序,现在它处于 QA 状态时,QA 工程师遇到了一个随机问题,在该问题中点击 USE 后出现黑屏UIImagePickerController。在图像中进一步didFinishPickingMediaWithInfo保存以供将来参考并显示在 中UIImageView,我还使用相机叠加层向 中添加按钮,UIImagePickerView并且应用程序的最大内存使用量不超过13 MB。从拍摄模式切换到相机胶卷模式时不会出现此问题。同样的观点iADs也正在呈现。下面是问题可能涉及的代码,还附加了图像以了解问题。任何帮助将不胜感激。

提前致谢。

图像选择器控制器

这张图片是正确的,这就是应该如何呈现视图

在点击使用后随机出现此屏幕,尽管在导航到其他选项卡时会出现正确的屏幕 [屏幕编号 2]。

(void) launchCamera 
{
     // Set up the camera\
     CustomCameraView *cameraController   = [[CustomCameraView alloc] init];  
     cameraController.sourceType          = UIImagePickerControllerSourceTypeCamera;
     cameraController.delegate            = self; 
     cameraController.showsCameraControls = YES;
     cameraController.navigationBarHidden = YES;
     cameraController.toolbarHidden       = YES;

     // overlay on top of camera lens view

     UIButton *cameraRoll = [[UIButton alloc] initWithFrame:CGRectMake(15, 380, 40, 40)];
     [cameraRoll setAlpha:0.0f];
     [cameraRoll setBackgroundImage:[UIImage imageNamed:@"CamerRoll_New"] forState:UIControlStateNormal];
     [cameraRoll addTarget:self action:@selector(switchToCameraRoll) forControlEvents:UIControlEventTouchUpInside];
     cameraController.cameraOverlayView = cameraRoll;

     [UIView beginAnimations:nil context:NULL];
     [UIView setAnimationDelay:1.5f];
     cameraRoll.alpha = 1.0f;
     [UIView commitAnimations];

     [self presentModalViewController:cameraController animated:YES];

 }

-(void)switchToCameraRoll
{
    DLog(@"Camera Roll");  
    [self dismissViewControllerAnimated:NO completion:^(void){ [self photoSourcePhotoAlbum];}];
}

-(void) photoSourcePhotoAlbum
{
     UIImagePickerController * picker = [[UIImagePickerController alloc] init];
     picker.delegate = self;
     picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
     [self presentModalViewController:picker animated:YES];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{    
    [self.view addSubview:progressView];
    timer = [NSTimer scheduledTimerWithTimeInterval:.017 target:self selector:@selector(progressChange) userInfo:nil repeats:YES];
    [picker dismissModalViewControllerAnimated:YES];
    [self performSelectorInBackground:@selector(saveImage:) withObject:info];
    [self performSelector:@selector(navigateToEditView) withObject:nil afterDelay:2.1];
}

-(void)navigateToEditView
{
    [self performSegueWithIdentifier:@"presentRDetailModalViewController" sender:self];   
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    if (picker.sourceType == UIImagePickerControllerSourceTypeSavedPhotosAlbum) 
    {
        [picker dismissViewControllerAnimated:NO completion:^(void){ [self photoSourceCamera];}];
    }
    else 
    {
        [picker dismissModalViewControllerAnimated:YES]; 
    }
}

-(void)saveImage:(NSDictionary *)info
{    
    NSString *imageName = [[[DataStaging dataStaging] getGUID] stringByAppendingString:@".jpg"];
    rImageName = imageName;
    UIImage *rImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    //Compress image

    [[FileOperations fileOperations] PersistData:UIImageJPEGRepresentation(rImage, 0.4) name:imageName];
    DLog(@"%@",[[FileOperations fileOperations] fetchPath:imageName]);

    //Actual image taken

    [[self rImageView] setImage:[info objectForKey:@"UIImagePickerControllerOriginalImage"]];

    if ([rImageName length] == 0) 
    {
        [[self rDetails] setHidden:YES];
        [[self trashRImage]   setHidden:YES];
    }
    else 
    {
        [[self rDetails] setHidden:NO];

        [[self trashRImage]   setHidden:NO];
    }

    [progressView removeFromSuperview];
  }
}
4

1 回答 1

0

确保您没有调用 presentModalViewController:animated: 在 dismissModalViewControllerAnimated: 之前两次:它对我的情况有所帮助。

- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
{
    if (_imagePickerController!=nil || _imagePopoverController!=nil) {
        return;
    }
    _imagePickerController = [[[UIImagePickerController alloc] init] autorelease];
    _imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
    _imagePickerController.sourceType = sourceType;
    _imagePickerController.delegate = self;
    switch (sourceType) {
        case UIImagePickerControllerSourceTypeCamera:
            _imagePickerController.showsCameraControls = YES;
            [self presentViewController:_imagePickerController animated:YES completion:nil];
            break;
        default:
            _imagePopoverController = [[UIPopoverController alloc] initWithContentViewController:_imagePickerController];
            _imagePopoverController.delegate = self;
            CGRect rect = [[UIScreen mainScreen] bounds];
            rect.origin.y = rect.size.height - 70.0;
            rect.size.height -= rect.origin.y;
            [_imagePopoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
            break;
    }
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker
{
    [_imagePopoverController dismissPopoverAnimated:YES];
    _imagePopoverController = nil;
    [_imagePickerController dismissViewControllerAnimated:YES completion:nil];
    _imagePickerController = nil;
}

- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
    UIImageWriteToSavedPhotosAlbum([info objectForKey:UIImagePickerControllerOriginalImage],nil,nil,nil);
    _currentImage = [info objectForKey:UIImagePickerControllerOriginalImage];

    [_imagePopoverController dismissPopoverAnimated:YES];
    _imagePopoverController = nil;
    [_imagePickerController dismissViewControllerAnimated:YES completion:nil];
    _imagePickerController = nil;
}
于 2013-07-30T19:43:51.193 回答