【问题标题】:Add a Subview to Splashscreen将子视图添加到启动画面
【发布时间】:2011-10-04 12:14:52
【问题描述】:

我目前正在尝试将活动指示器视图添加到我的启动画面。它应该只出现一次 - 在应用程序的第一次启动时。创建了一些应用程序所需的图像,但这需要一些时间。

创建图像时,启动画面仍然可见。所以我认为有可能添加一个活动指示器作为 Splashscreen 的子视图,或者至少以某种方式在 Splashscreen 上添加它。

有没有可能做到这一点?

提前感谢您的帮助。

【问题讨论】:

    标签: iphone splash-screen uiactivityindicatorview


    【解决方案1】:

    您需要将“Splashscreen”作为最顶层视图添加到您的窗口,“splashcreen”本身不是视图。系统只会显示default.png:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
    
        splashScreen = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, -20.0f, 320.0f, 480.0f)];
        splashScreen.backgroundColor = [UIColor blackColor];
        splashScreen.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default" ofType:@"png"]];
        [self.window addSubview:splashScreen];
    
        [self.window makeKeyAndVisible];
    
        [self performSelector:@selector(applicationDidStart) withObject:nil afterDelay:0.1];
    
        return YES;
    }
    

    splashScreen 是一个类变量,你可以在 splashView 中添加一个 Activity Indicator。

    然后在applicationDidStart do start 方法中放置需要一些时间的代码:

    - (void) applicationDidStart {
        // some thing that takes a while
    
       [splashScreen removeFromSuperView];
       [splashScreen release], splashScreen = nil;
    }
    

    【讨论】:

    • 我认为他说“SplashScreen”时指的是启动图像。虽然你可能是对的,而我的看法可能是错误的。
    • 这是在“SplashScreen”中添加引号的方式;)
    • 谢谢,它现在工作正常 :) 是的,我的意思是启动图像。在 WP7 中它被称为 Splashscreen ;)
    【解决方案2】:

    我认为不可能将子视图添加到启动画面。

    有一种解决方法,您可以在 applicationDidFinishLaunching 上推送一个中间视图,并使该视图的背景图像与初始屏幕的背景图像相同。

    现在您可以在此视图上执行创建图像的操作了。

    创建图像后,在 applicationDelegate 中调用一个方法,该方法将弹出中间视图并添加您的常规视图。

    希望对你有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-13
      • 2011-01-21
      • 2021-11-02
      • 2015-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多