将 UIActivityIndi​​cator 添加到模态视图(ELCimagepicker)

发布于 2024-11-10 09:03:37 字数 1470 浏览 4 评论 0原文

我已将 ELCimagepicker (https://github.com/Fingertips/ELCImagePickerController) 添加到我的项目中,它运行良好,允许用户为幻灯片选择多个图像。但是,当您单击“保存”时,可能会出现较长的延迟,具体取决于添加的照片数量。

我一直在尝试在用户单击“保存”时添加 UIActivityIndi​​cator,但由于显示的模式视图而遇到问题。我可以从 ELCimagepicker 呈现的活动 (ELCImagePickerController) 调用一个方法,并且该方法由处理图像选择器呈现的活动执行。但每当我尝试添加到视图时,它都不会显示,因为模式位于活动指示器的顶部。

我尝试过使用bringSubviewToFront,我尝试使用[[selfparentViewController]addSubView]将代码直接添加到imagepicker方法文件中,但没有运气。

这是我尝试的最新代码:(指示器在 .h 文件中声明为 UIActivityIndi​​cator *indicator)

 indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.hidden=false;

[self.navigationController.view addSubview:self.indicator];
[self.navigationController.view bringSubviewToFront:self.indicator];

[indicator startAnimating];

if([delegate respondsToSelector:@selector(elcImagePickerController:showIndicator:)]) {
    [delegate performSelector:@selector(elcImagePickerController:showIndicator:) withObject:self withObject:@"test"];
}

有没有人在 ELCimagepicker 或由另一个类处理的另一个模态视图之上添加 UIActivityIndi​​cator 取得过任何成功?

我已经尝试过 MBProgressHUD 但也无法使其正常工作 - 当我在 ELCimagepicker 类中使用它时它会显示出来,但在删除时崩溃:

bool _WebTryThreadLock(bool), 0x42368e0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...

任何帮助都会很棒。

谢谢。

I've added the ELCimagepicker (https://github.com/Fingertips/ELCImagePickerController) to my project and it works perfectly, allowing the user to select multiple images for a slideshow. But when you click 'Save', there can be a lengthy delay depending on how many photos were added.

I've been trying to add a UIActivityIndicator when the user clicks 'Save', but having trouble due to the modal view that is presented. I can call a method from the activity that ELCimagepicker presents (ELCImagePickerController) and this gets actioned by the activity handling the presenting of the image picker. But whenever I try to add to the view, it isn't shown as the modal is on top of the activity indicator.

I've tried using bringSubviewToFront, I've tried adding the code directly to the imagepicker method file with [[self parentViewController] addSubView], but no luck.

Here's the latest code I tried: (indicator is declared in the .h file as UIActivityIndicator *indicator)

 indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.hidden=false;

[self.navigationController.view addSubview:self.indicator];
[self.navigationController.view bringSubviewToFront:self.indicator];

[indicator startAnimating];

if([delegate respondsToSelector:@selector(elcImagePickerController:showIndicator:)]) {
    [delegate performSelector:@selector(elcImagePickerController:showIndicator:) withObject:self withObject:@"test"];
}

Has anyone had any success with adding a UIActivityIndicator on top of the ELCimagepicker, or another modal view handled by another class?

I've tried MBProgressHUD but couldn't get that working quite right either - it would show up when I used it in the ELCimagepicker class, but crashed on removal with:

bool _WebTryThreadLock(bool), 0x42368e0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...

Any help would be fantastic.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅听莫相离 2024-11-17 09:03:37

我已经弄清楚你的问题了。您可以按如下方式执行此操作。

-(void)selectedAssets:(NSArray*)_assets {

UIActivityIndicatorView * activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
UIViewController * topView = [self.viewControllers objectAtIndex:[self.viewControllers count]-1];
activityIndicator.center = CGPointMake(topView.view.frame.size.width/2, topView.view.frame.size.height/2);
[activityIndicator setHidden:NO];
[topView.view addSubview:activityIndicator];
[topView.view bringSubviewToFront:activityIndicator];
[activityIndicator startAnimating];

[self performSelector:@selector(doProcess:) withObject:_assets afterDelay:2.1];

}

- (void) doProcess:(NSArray *)_assets {

NSMutableArray *returnArray = [[[NSMutableArray alloc] init] autorelease];

for(ALAsset *asset in _assets) {

    NSMutableDictionary *workingDictionary = [[NSMutableDictionary alloc] init];
    [workingDictionary setObject:[asset valueForProperty:ALAssetPropertyType] forKey:@"UIImagePickerControllerMediaType"];
    [workingDictionary setObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]] forKey:@"UIImagePickerControllerOriginalImage"];
    [workingDictionary setObject:[[asset valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]] forKey:@"UIImagePickerControllerReferenceURL"];

    [returnArray addObject:workingDictionary];

    [workingDictionary release];    
}

[self popToRootViewControllerAnimated:NO];
[[self parentViewController] dismissModalViewControllerAnimated:YES];

if([delegate respondsToSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:)]) {
    [delegate performSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:) withObject:self withObject:[NSArray arrayWithArray:returnArray]];
}

}

如果这个答案对您有帮助,请告诉我...

谢谢,
米努大师

I have figure out your problem. You can do this as below..

-(void)selectedAssets:(NSArray*)_assets {

UIActivityIndicatorView * activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
UIViewController * topView = [self.viewControllers objectAtIndex:[self.viewControllers count]-1];
activityIndicator.center = CGPointMake(topView.view.frame.size.width/2, topView.view.frame.size.height/2);
[activityIndicator setHidden:NO];
[topView.view addSubview:activityIndicator];
[topView.view bringSubviewToFront:activityIndicator];
[activityIndicator startAnimating];

[self performSelector:@selector(doProcess:) withObject:_assets afterDelay:2.1];

}

- (void) doProcess:(NSArray *)_assets {

NSMutableArray *returnArray = [[[NSMutableArray alloc] init] autorelease];

for(ALAsset *asset in _assets) {

    NSMutableDictionary *workingDictionary = [[NSMutableDictionary alloc] init];
    [workingDictionary setObject:[asset valueForProperty:ALAssetPropertyType] forKey:@"UIImagePickerControllerMediaType"];
    [workingDictionary setObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]] forKey:@"UIImagePickerControllerOriginalImage"];
    [workingDictionary setObject:[[asset valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]] forKey:@"UIImagePickerControllerReferenceURL"];

    [returnArray addObject:workingDictionary];

    [workingDictionary release];    
}

[self popToRootViewControllerAnimated:NO];
[[self parentViewController] dismissModalViewControllerAnimated:YES];

if([delegate respondsToSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:)]) {
    [delegate performSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:) withObject:self withObject:[NSArray arrayWithArray:returnArray]];
}

}

Let me know if this answer help you ...

Thanks,
MinuMaster

十秒萌定你 2024-11-17 09:03:37

看起来您正在后台线程上更新 UI。所有 UIKit 更新都将在主线程中完成。因此,我建议您使用 performSelectorOnMainThread:withObject: 执行执行 UI 更新的方法。

It looks like you are updating UI on a background thread. All UIKit updates are to be done in the main thread. So I recommend you execute methods doing UI updates using performSelectorOnMainThread:withObject:.

不美如何 2024-11-17 09:03:37

我这样解决了这个问题

     activityIndicatorObject = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

     // Set Center Position for ActivityIndicator

     activityIndicatorObject.center = CGPointMake(150, 250);
     activityIndicatorObject.backgroundColor=[UIColor grayColor];

     // Add ActivityIndicator to your view
     [self.view addSubview:activityIndicatorObject];

     activityIndicatorObject.hidesWhenStopped=NO;

     [activityIndicatorObject startAnimating];

I solved the issue like this

     activityIndicatorObject = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

     // Set Center Position for ActivityIndicator

     activityIndicatorObject.center = CGPointMake(150, 250);
     activityIndicatorObject.backgroundColor=[UIColor grayColor];

     // Add ActivityIndicator to your view
     [self.view addSubview:activityIndicatorObject];

     activityIndicatorObject.hidesWhenStopped=NO;

     [activityIndicatorObject startAnimating];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文