2014-01-29 161 views
3

在我的應用程序中,我想讓初始屏幕成爲動畫我正在使用下面的代碼,但動畫無效。iOS初始屏幕動畫

UIImageView *splashScreen = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"Default.png"]]; 
[self.window.rootViewController.view addSubview: splashScreen]; 

[self.window makeKeyAndVisible]; 

NSLog(@"begin splash"); 
[UIView animateWithDuration: 0.2 
         delay: 0.5 
        options: UIViewAnimationOptionCurveEaseOut 
       animations: ^{splashScreen.alpha = 0.0; 
       } 
       completion:^(BOOL finished) { 
        [splashScreen removeFromSuperview]; 
        NSLog(@"end splash"); 
       } 
]; 
+0

你想要一個閃屏? Y這很複雜 – chandru

+0

您的默認屏幕非常漂亮,我想看到它比我需要更長的時間?我對此表示懷疑。準備就緒後,我寧願開始使用該應用程序。大多數人也是如此。 – Abizern

+0

你在哪裏可以在rootViewController的viewDidLoad或其他地方使用這段代碼 – channi

回答

6

您不能爲動畫圖像設置動畫,但您可以等到應用程序啓動並使用動畫添加自己的視圖。

6

你不得不採用一些技巧,將實現

打開AppDelegate.m和下面的代碼添加到您的應用程序didFinishLaunching或應用程序didFinishLaunchingWithOptions功能:

//1. add the image to the front of the view... 
UIImageView *splashImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
[splashImage setImage: [UIImage imageNamed:@"Default"]]; 
[self.window addSubview:splashImage]; 
[self.window bringSubviewToFront:splashImage]; 

//2. set an anchor point on the image view so it opens from the left 
splashImage.layer.anchorPoint = CGPointMake(0, 0.5); 

//reset the image view frame 
splashImage.frame = CGRectMake(0, 0, 320, 480); 

//3. animate the open 
[UIView animateWithDuration:1.0 
         delay:0.6 
        options:(UIViewAnimationCurveEaseOut) 
       animations:^{ 

        splashImage.layer.transform = CATransform3DRotate(CATransform3DIdentity, -M_PI_2, 0, 1, 0); 
       } completion:^(BOOL finished){ 

        //remove that imageview from the view 
        [splashImage removeFromSuperview]; 
       }]; 

download sample app

animated-splash-screen-default-png