2010-07-15 54 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]; 
相關問題