开发者

Fade from iPhone default bitmap into main app

开发者 https://www.devze.com 2022-12-17 03:40 出处:网络
What\'s the easiest/fastest/most efficient way to perform a gradual (0.5 sec) fade from Default.png to the initial app view?

What's the easiest/fastest/most efficient way to perform a gradual (0.5 sec) fade from Default.png to the initial app view?

My initial try, which doesn't work so well .. it's Saturday night, let's see if we can do better :)

UIImageView* whiteoutView = [[UIImageView alloc] initWithFrame:self.view.frame]; // dealloc this later ??
whiteoutView.image = [UIImage imageNamed:@"Default.png"];
whiteoutView.alpha = 1.0;
[self.view.frame addSubview:whiteoutView];
[UIView beginAnimations:nil context开发者_Go百科:nil];
[UIView setAnimationDelay:0.5];
whiteoutView.alpha = 0;
[UIView commitAnimations];


What about:

UIImageView* whiteoutView = [[[UIImageView alloc] initWithFrame:self.view.frame] autorelease];
if (whiteoutView != nil)
{
    whiteoutView.image = [UIImage imageNamed:@"Default.png"];
    [self.view addSubview:whiteoutView];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration: 0.5];
    whiteoutView.alpha = 0.0;
    [UIView commitAnimations];
}

(The things you had wrong were setAnimationDelay vs setAnimationDuration, not properly releasing the view and trying to add the view to self.view.frame instead of self.view. The compiler should have caught that last one. Did it?)


Here's a simple view controller that fades out the default image and removes itself from the view hierarchy. The advantage to this approach is that you can use this without modifying your existing view controllers...

@interface LaunchImageTransitionController : UIViewController {}
@end
@implementation LaunchImageTransitionController

- (void)viewDidLoad {
  [super viewDidLoad];

  self.view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]] autorelease];
  [UIView beginAnimations:nil context:nil];
  [UIView setAnimationDuration:.5];
  [UIView setAnimationDelegate:self];
  [UIView setAnimationDidStopSelector:@selector(imageDidFadeOut:finished:context:)];
  self.view.alpha = 0.0;
  [UIView commitAnimations];

}
- (void)imageDidFadeOut:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
  [self.view removeFromSuperview];
  //NOTE: This controller will automatically be released sometime after its view is removed from it' superview...
}
@end

Here is how you might use it in your app delegate:

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

  //create your root view controller, etc...
  UIViewController *rootController = ....

  LaunchImageTransitionController *launchImgController = [[[LaunchImageTransitionController alloc] init] autorelease];

  [window addSubview:rootController.view];
  [window addSubview:launchImgController.view];

  [window makeKeyAndVisible];
} 


Other than using setAnimationDelay: instead of setAnimationDuration:, it looks pretty good. What don't you like about the results?

Edit: Wow beaten hard.

0

精彩评论

暂无评论...
验证码 换一张
取 消