【问题标题】:iPhone UIImagePickerController problem: want to show UIActivityIndicatorView after hit "Use" buttoniPhone UIImagePickerController 问题:点击“使用”按钮后想要显示 UIActivityIndi​​catorView
【发布时间】:2010-11-21 01:51:52
【问题描述】:

当 Apple 推出 3.0 版 iPhone 操作系统时,UIImagePickerController 略有变化:在用户确认最近拍摄的照片后,它不再提供活动或进度指示器。简而言之,你现在 - 拍照, - 决定没关系 - 点击“使用”按钮并等待。 没有迹象表明您是否真的点击了“使用”按钮。通常,我打了好几次,因为我不确定我是否真的打了它。几秒钟后,您会看到图像或图像通过委托连接可用,例如

  • (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

我的问题是: - 如何在选择“使用”按钮后立即显示 UIActivityIndi​​catorView?或者,如何通过拦截“使用”按钮回调来插入自己的代码?我在网上搜索过,预计会有很多人遇到同样的问题,但还没有找到解决方案。

谢谢。

【问题讨论】:

    标签: iphone android-activity uiimagepickercontroller progress


    【解决方案1】:

    很遗憾,您无法拦截此呼叫。我这样说是因为 UIImagePickerController 中没有委托方法可以告诉委托有关按下使用按钮的信息。由于您无法更改 UIImagePickerController 中的代码,因此我认为您无能为力。 Apple 可能会在 3.1 中改进这一点,我听说他们在 UIImagePickerController 上做了一些工作......

    【讨论】:

    • 从我看到的 3.1 api 文件中你仍然看不到,但这一切都可能在周三改变
    【解决方案2】:

    您实际上可以做的就是在您关闭它之前将您的 UIActivityInidicatior 添加到 UIImagePicker 视图中。

    这是我在用户按下使用按钮后压缩图像时正在做的类似事情。注意 NSTimer - 这是一个让 iphone 真正显示您正在添加的 UI 的绝妙技巧: 在 didFinishPickingImage 上:

    //this will add the UIActivityInidicatior to the picker view
    
    (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo { 
     showActivity(@"Compressing Image", picker.view);
    
     //this is a hack so the progress label will show up
    
    [NSTimer scheduledTimerWithTimeInterval: 0.0f
                                         target: self
                                       selector: @selector(compress:)
                                       userInfo: image
                                        repeats: NO];
    }
    
    
    
    
    //the Compress method
    
    (void) compress:(NSTimer *)inTimer {
     NSAutoreleasePool *_pool = [[NSAutoreleasePool alloc] init];
    
     //do some work
    
    
       [[self getPicker] dismissModalViewControllerAnimated:YES]; 
    
    //dismiss the view we added to the picker
     showActivity(nil, [self getPicker].view);
    
     [_pool release];
    
    }
    

    请注意,我将UIImagePickerController 保留在外部,因此我可以从调用的消息中引用它。

    showActivity 是一种向给定视图添加一些 UI 的简单方法。

    【讨论】:

    • 你能发布你的完整代码吗?我也在寻找类似的东西
    【解决方案3】:

    通过调度队列的概念,

    当您按下使用按钮时,它将在一个线程中关闭pickercontroller,并显示活动指示器代码将在另一个线程中运行。在这两者之间,您可以调用自己的方法。

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    dispatch_async(dispatch_get_main_queue(), ^{
    
      indicator=[[MBProgressHUD alloc]init];
      indicator.labelText=@"Loading";
      indicator = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
      [indicator show:YES];
    
    
    });
    
    // Put here the code to resize the image
    [self performSelectorInBackground:@selector(setPath:) withObject:image];
    
    dispatch_async(dispatch_get_main_queue(), ^{
      [picker dismissModalViewControllerAnimated:YES];
    
    });
    

    如果你想在 uiimagepickercontroller 中显示活动指示器意味着只需更改此行

      indicator=[[MBProgressHUD alloc]init];
      indicator.labelText=@"Loading";
      indicator = [MBProgressHUD showHUDAddedTo:picker.cameraOverlayView animated:YES];
      [indicator show:YES];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-14
      相关资源
      最近更新 更多