将子视图添加到闪屏

发布于 2024-12-08 04:57:39 字数 190 浏览 0 评论 0原文

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

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

有可能使这成为可能吗?

提前感谢您的帮助。

I am currently trying to add a Activity Indicator View to my Splashscreen. It only should appear once - at the first start of the App. Some images are created that are needed for the App, but it takes some time.

While the images are created, the Splashscreen is still visible. So I thought it could maybe be possible to add a Activity Indicator as a Subview of the Splashscreen or at least add it somehow over the Splashscreen.

Is there a possibility to make this possible?

Thanks for your help in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌若浮生 2024-12-15 04:57:39

您需要将“启动画面”添加为窗口的最顶层视图,“启动画面”本身不是视图。系统只会显示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添加一个活动指示器。

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

- (void) applicationDidStart {
    // some thing that takes a while

   [splashScreen removeFromSuperView];
   [splashScreen release], splashScreen = nil;
}

You will need to add the "Splashscreen" as top most view to your window, the "splashcreen" it self is not a view. The system wil just display the 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 is a class variable, you could add an Activity Indicator to the splashView.

Then in the applicationDidStart did start methods place the code that will take some time:

- (void) applicationDidStart {
    // some thing that takes a while

   [splashScreen removeFromSuperView];
   [splashScreen release], splashScreen = nil;
}
故事灯 2024-12-15 04:57:39

我认为不可能向启动屏幕添加子视图。

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

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

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

希望这对您有帮助。

I dont think it is possible to add a subview to the Splash Screen.

There is a workaround where in you can push an intermediate view on applicationDidFinishLaunching and have the background image of the view as same as that of the splash screen.

Now you can do the stuff where your images are created on this view.

Once images are created, Call a method in applicationDelegate which will pop the intermediate view and add your regular view.

Hope this helps you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文