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

时间:2011-05-28 09:45:16

标签: iphone modalviewcontroller uiactivityindicatorview addsubview

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

当用户点击“保存”时,我一直在尝试添加UIActivityIndi​​cator,但由于显示的模态视图而出现问题。我可以从ELCimagepicker提供的活动中调用一个方法(ELCImagePickerController),这可以通过处理图像选择器呈现的活动来执行。但每当我尝试添加到视图时,它都不会显示为模态位于活动指示器之上。

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

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

 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...

任何帮助都会很棒。

感谢。

3 个答案:

答案 0 :(得分:4)

我找出了你的问题。你可以这样做..

-(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]];
}

}

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

谢谢, MinuMaster

答案 1 :(得分:1)

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

答案 2 :(得分:0)

我解决了这个问题

     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];