如何使用 NSTimer 使图像 Alpha 变化/淡入淡出?

发布于 2024-11-19 04:14:07 字数 265 浏览 3 评论 0原文

我正在 Xcode 中使用 Objective C 为 iphone 编写一个应用程序。我想做的是在我的应用程序启动时制作一个闪屏,持续大约 2 或 3 秒,我浏览了整个互联网,但所有关于如何执行此操作的教程都已过时,并且无法使用Xcode 和 Interface Builder 的当前版本。所以我想知道如何使用 NSTimer 发布图像大约 3 秒,然后将图像的 alpha 更改为 0。顺便说一句,我想知道如何在使用基于 Window 的应用程序预设时执行此操作。任何帮助将不胜感激,一个例子也可能会有所帮助。

I am programming an app for the iphone in Objective C in Xcode. What I am trying to do is to make a splash screen at the start of my app last for about 2 or 3 seconds, I have looked throughout the internet, but all of the tutorials on how to do this were outdated and did not work with the current versions of Xcode and Interface Builder. So I was wondering how would I use NSTimer to post an image for about 3 seconds and then change the alpha of the image to 0. By the way, I am wondering how to do this while using a Window Based Application preset. Any help would be greatly appreciated and an example would probably help as well.

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

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

发布评论

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

评论(2

注定孤独终老 2024-11-26 04:14:07

Apple 不喜欢看到闪屏。但如果您坚持的话,您是否尝试过仅设置 Default.png 图像?只需将名为 Default.png 的图像拖到应用程序的“资源”文件夹中,启动画面就会在启动时显示。

信息: Default.png 的真正目的是让 UI 在应用真正准备好之前显示为“几乎准备好”状态,而这正是 Apple 想让您使用的这是为了,但应用程序不会因为在其启动屏幕上使用此功能而被拒绝。

Apple does not like seeing splashscreens. But if you're insisting, have you tried just setting a Default.png image? Just drag an image called Default.png into your App's "Resources" folder and your splashscreen will be shown at startup.

Info: The real purpose of Default.png is to make the UI appear in an "almost ready" state before the app is actually ready and that's what Apple intends you to use this for, but apps don't get rejected for using this function for their Splashscreens.

扭转时空 2024-11-26 04:14:07

@大卫希弗是正确的。有关详细信息,请参阅 Apple 文档(向下滚动到应用程序启动图像)。

但是,如果您想实际实现某些内容,则可以按照建议进行操作并使用标准机制。然后

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

你可以在图像视图中抛出相同的图像(你的飞溅),然后使用像这样的动画块。

[UIView animateWithDuration:0.5
                      delay:3
                    options:UIViewAnimationCurveLinear
                 animations:^{
                    myImageView.alpha = 0;
                 }
                 completion:^(BOOL finished){
                    [myImageView removeFromSuperview];
                 }];

如果您每次启动应用程序时都需要它,请添加到此

- (void)applicationDidBecomeActive:(UIApplication *)application

@David Schiefer is correct. For more info see the Apple Docs (scroll down to Application Launch Images).

But if you wanted to actually implement something regardless you can do as suggested and use the standard mechanism. Then in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

you could throw up the same image (your splash) in an imageview then use animation blocks like this.

[UIView animateWithDuration:0.5
                      delay:3
                    options:UIViewAnimationCurveLinear
                 animations:^{
                    myImageView.alpha = 0;
                 }
                 completion:^(BOOL finished){
                    [myImageView removeFromSuperview];
                 }];

If you want it every time the app is launched add to this instead

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