我有一个图像选择器可以从照片库中选择多个图像。挑选的照片会调整大小并保存到imagePickerController:didFinishPickingMediaWithInfo:
中的文件中。这需要几秒钟。
我可以在视图上放一个指示器吗?
我尝试在addSubview:indicatorView
方法中使用imagePickerController:didFinishPickingMediaWithInfo:
。但 indicatorView 不会出现。它会被imagePickerView解雇。
答案 0 :(得分:3)
您应该在视图层次结构的顶部添加UIActivityIndicatorView,否则它将被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
});
});