How to use NSTimer to make an image alpha change/fade?
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 we开发者_如何学运维re 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.
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.
@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
精彩评论