2010-07-15 57 views
0

我想在modalViewController上添加一个activityIndi​​cator。在modalViewController上添加一个activityIndi​​cator iphone

基本上我想在用户按下这个modalViewController上的一个按钮后开始动画这个activityIndi​​cator。但是发生了什么事情是我在做这个modalViewController的时候使用的presentModalViewController保持不变,即使我只是简单地添加activityIndi​​cator,然后展示了modalView,然后即使我启动它也不会显示出来。但如果之前preseting这个modalViewController,如果我开火[活动startAnimating];然后在呈现modalView活动后显示动画。

所以基本上,我想简单地在modalViewController上添加activityIndi​​cator并在按下按钮后开始动画。

我用下面的代码:

imageUploadView = [[UIViewController alloc]initWithNibName:nil bundle:nil]; 
    CGRect frame = CGRectMake(140.0, 410.0, 25.0, 25.0); 
    loading = [[UIActivityIndicatorView alloc] initWithFrame:frame]; 
    [loading sizeToFit]; 
    loading.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | 
    UIViewAutoresizingFlexibleRightMargin | 
    UIViewAutoresizingFlexibleTopMargin | 
    UIViewAutoresizingFlexibleBottomMargin); 

    [imageUploadView.view addSubview:loading]; 
    [_picker_ presentModalViewController:imageUploadView animated:YES]; 

任何人可以请帮助?

Thanx提前。

回答

0

将其添加为子视图。

+0

能否请您具体?我有点困惑.. – neha 2010-07-15 13:52:18

+0

只要你的看法,并调用'[whatevertheviewis addSubview:anactivityindicatorview];' – jrtc27 2010-07-15 14:40:53

1

内,您的视图控制器,在viewDidLoad中或在viewWillAppear中试试这个:

CGRect frame = CGRectMake(140.0, 410.0, 25.0, 25.0); 
    loading = [[[UIActivityIndicatorView alloc] initWithFrame:frame] autoRelease]; 
    [loading sizeToFit]; 
    loading.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | 
    UIViewAutoresizingFlexibleRightMargin | 
    UIViewAutoresizingFlexibleTopMargin | 
    UIViewAutoresizingFlexibleBottomMargin); 
    [self.view addSubView:loading]; 
    loading.startAnimateing 
+0

倒数第二行需要是“addSubview”,没有大写“v”。 – DenVog 2013-03-01 02:14:29

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]; 
相关问题