如何将UIActivityIndi​​cator添加到我的应用程序的Splash屏幕?

时间:2013-08-02 05:56:31

标签: ios objective-c splash-screen uiactivityindicatorview

是否可以将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;
}

请帮帮我

2 个答案:

答案 0 :(得分:3)

您应用的启动画面只是一个静态的png文件。您不能像微调器或动画那样添加任何内容。但是,您可以执行的操作是,一旦启动屏幕完成加载,您就可以显示同样具有相同启动画面的视图,然后以编程方式或使用界面构建器添加微调器。基本上从用户的角度来看,他们无法区分。

我之前使用过这种技术,效果很好。

顺便说一句,您的睡眠呼叫会暂时冻结您的应用程序。您最好使用NSTimer,以便操作系统不会终止您的应用程序而不响应。

答案 1 :(得分:2)

试试这个......

UIImageView * splashView; //在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:@"Default-568h@2x.png"];
    }
    else
    {
        splashView.image = [UIImage imageNamed:@"Default.png"];
    }

    [self.window addSubview:splashView];

   // Add your spinner here.

    return YES;
}

希望我帮助过。