【问题标题】:How to add an Indicator to UIImagePickerController如何向 UIImagePickerController 添加指标
【发布时间】:2012-05-14 00:54:59
【问题描述】:

我有一个图像选择器,可以从照片库中选择多张图像。选择的照片将调整大小并保存到imagePickerController:didFinishPickingMediaWithInfo: 中的文件。这需要几秒钟。

我可以在视图上放置一个指示器吗? 我尝试在imagePickerController:didFinishPickingMediaWithInfo: 方法中使用addSubview:indicatorView。但是 indicatorView 没有出现。它会被 imagePickerView 解散。

【问题讨论】:

    标签: iphone ios uiimagepickercontroller uiactivityindicatorview


    【解决方案1】:

    您应该在视图层次结构的顶部添加 UIActivityIndi​​catorView,否则它将被 UIPickerViewController 关闭,除非您在调整大小操作后使用回调并且在回调中关闭 UIImagePickerController。

    或者你可以使用像SVProgressHUD这样的进度HUD。

    希望这会有所帮助 =)

    我们做了一个小小的聊天会话并以这种方式解决了:

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
        dispatch_async(dispatch_get_main_queue(), ^{ 
              UIView *primaryImage = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,460)]; 
              primaryImage.backgroundColor = [UIColor redColor]; 
              primaryImage.alpha =0.9; 
    
              UIView *secondaryImage = [[UIView alloc] initWithFrame:CGRectMake(0,0,70,70)]; 
              secondaryImage.center = CGPointMake(160, 240); 
              secondaryImage.backgroundColor = [UIColor blackColor]; 
              secondaryImage.alpha = 0.9; 
              secondaryImage.layer.cornerRadius = 12; 
              [primaryImage addSubview:secondaryImage]; 
              UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 25, 25)]; 
              indicator.center = CGPointMake(35, 35); 
              [indicator setHidesWhenStopped:NO]; 
              [secondaryImage addSubview:indicator]; 
              [indicator startAnimating]; 
    
              [indicator release]; 
              [secondaryImage release]; 
    
              [picker.view addSubview:primaryImage]; 
    
             [primaryImage release]; 
         }); 
    
        // Put here the code to resize the image 
    
        dispatch_async(dispatch_get_main_queue(), ^{ 
        // Dismiss the picker controller
    
        });
    });
    

    【讨论】:

    • 是的,我把它放在视图层次结构的顶部,但它没有出现,直到解雇动画时期。这就是我的意思“它会被 UIPickerViewController 解散”。
    • 对于“在视图层次结构的顶部”,我的意思是在 UIWindow 中。无论如何,您可以尝试在创建 UIPickerController 并使用 ivar 控制它时添加 UIIndicatorView。
    • 你的意思是添加到窗口?让我试试,还是不行。是的,我已经创建了一个指标并首先将其隐藏,但是一旦我将隐藏设置为 NO,它就不起作用了。
    • 指标是 UIActivityIndi​​catorView 实例吗?如果是,则应使用 hidesWhenStopped,然后在调用 startAnimating 方法时可见。
    • 其实我把indicatorView放在anotherUIView旁边。如[anotherUIView addSubview:indicator];并尝试控制另一个UIView隐藏和显示。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-09
    • 2021-11-20
    • 1970-01-01
    • 1970-01-01
    • 2015-08-15
    • 2019-01-07
    • 2013-12-23
    相关资源
    最近更新 更多