2013-08-02 23 views
1

是否可以添加UIActivityIndi​​cator來啓動我的應用程序的屏幕?如何將UIActivityIndi​​cator添加到我的應用程序的開機畫面?

蔭使用下面的代碼delegate.m文件和它的工作不適合我。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 

    [NSThread sleepForTimeInterval:5.0]; //for running splash screen more time 
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 

    spinner.center = CGPointMake(139.5, 75.5); // .5 so it doesn't blur 
    [self.view addSubview:spinner]; 
    [spinner performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.0]; 


    return YES; 
} 

請幫我

+1

看看這個http://stackoverflow.com/questions/9400193/adding-an-activity-indicator-programmatically-to-a-view –

+0

從不睡覺一個線程,使用通知或委託在操作開始時進行通信或完成 – Andrea

+0

@Andrea睡眠有問題嗎? – Navi

回答

2

試試這個...

UIImageView * splashView; // Declare in appDelegate.h

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    splashView = [[UIImageView alloc]initWithFrame:self.window.bounds]; 
    if (self.window.bounds.size.height > 480) 
    { 
     splashView.image = [UIImage imageNamed:@"[email protected]"]; 
    } 
    else 
    { 
     splashView.image = [UIImage imageNamed:@"Default.png"]; 
    } 

    [self.window addSubview:splashView]; 

    // Add your spinner here. 

    return YES; 
} 

希望我能幫上忙。

+0

如果可能,請始終使用MBProgressHUD進行加載。 –

3

您的應用程序的啓動畫面是一個簡單的PNG文件,它是靜態的。你不能像微調或動畫一樣添加任何東西。但是,您可以執行的操作是在啓動畫面完成加載後,您可以顯示也具有相同啓動畫面的視圖,然後以編程方式或使用界面構建器將微調器添加到該畫面。基本上從用戶的角度來看,他們無法區分差異。

我以前使用過這種技術,它工作得很好。

順便說一句,您的睡眠電話會暫時凍結您的應用程序。您最好使用NSTimer,以便操作系統不會因未響應而終止您的應用程序。

+0

謝謝。我添加了一個帶有動畫的uiactivity指示器作爲其初始狀態。現在工作 – Navi

相關問題