0

我想知道,在这种情况下如何显示 UIProgressView:我使用 UIImagePickerController 拍摄照片,然后在方法- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 中将图片保存到 UIImage 对象(outputImage)并隐藏控制器,当带有相机的 modalView/controller 消失时,我有这样的代码:

        NSLog(@"Image is width: %f height: %f", outputImage.size.width, outputImage.size.height);

        //FLIP PICTURE FROM FACETIME CAMERA
        if((outputImage.size.width == 480 && outputImage.size.height == 640) || (outputImage.size.width == 640 && outputImage.size.height == 480)) {
            outputImage = [UIImage imageWithCGImage:outputImage.CGImage
                                        scale:1.0 orientation: UIImageOrientationLeftMirrored];}

        //RESIZE TO 1000x1000
        outputImage = [self scaleAndCropToSize:outputImage toSize:CGSizeMake(1000, 1000)];

        NSLog(@"Now image is width: %f height: %f", outputImage.size.width, outputImage.size.height);

        //CUTING OUT TO MASK
        outputImage = [self maskImage:outputImage withMask:[UIImage imageNamed:@"mask.png"]];

        //ADDING SHADOW
        CGSize size = CGSizeMake(1000, 1000);
        UIGraphicsBeginImageContext(size);

        CGPoint thumbPoint = CGPointMake(0, 0);
        [outputImage drawAtPoint:thumbPoint];

        UIImage* shadow = [UIImage imageNamed:@"shadow.png"];

        CGPoint starredPoint = CGPointMake(0, 0);
        [shadow drawAtPoint:starredPoint];

        UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        outputImage = result;

        //ADDING TO UIIMAGEVIEW (PREVIEW)
        preview.image = outputImage;

将照片放入 UIImageView 时,需要一些时间。这次我想显示进度视图。我怎样才能做到这一点?

编辑:我想将上面的代码放在某个方法中,然后以某种方式实现progressview,这将基于方法完成时间。但不知道。

4

2 回答 2

2

您不能使用UIProgressView它,因为它很难知道执行图像操作需要多少时间。

你可以试试这个MBProgressHUD

把这段代码放进去didFinishPickingMediaWithInfo

MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.view];

HUD.labelText = @"Saving Image...";

[self.view  addSubview:HUD];

HUD.delegate = self;

[HUD showWhileExecuting:@selector(savingPicture:) onTarget:self withObject:selectedImage animated:YES];

并将您的调整大小/裁剪图像操作代码放在 savePicture 方法中。

于 2012-08-30T14:45:03.853 回答
0

当您正在运行一个循环并且您知道正在完成的工作的百分比时,进度视图更适合在进度条中显示进度。在这种情况下,您可以改为显示 UIActivityIndi​​cator,直到您的图像准备好放在图像视图上。

于 2012-08-30T14:36:38.677 回答