【问题标题】:iOS splash Screen AnimationiOS 闪屏动画
【发布时间】:2014-01-29 11:12:43
【问题描述】:

在我的应用程序中,我希望为启动画面设置动画我正在使用以下代码,但动画不起作用。

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");
                }
];

【问题讨论】:

  • 你想要一个启动画面?这么复杂
  • 您的默认屏幕是不是太漂亮了,以至于我想看它的时间比我需要的更长?我对此表示怀疑。我宁愿在应用程序准备好后立即开始使用。大多数人也会如此。
  • 你在 rootViewController 的 viewDidLoad 或其他任何地方使用过这段代码
  • 这篇文章解释了更多动态启动屏幕的一些可能性:blog.hawkimedia.com/2014/10/dynamic-interactive-launch-screens

标签: ios animation splash-screen


【解决方案1】:

您无法为启动图像设置动画,但您可以等到应用启动后再添加您自己的带有动画的视图。

【讨论】:

    【解决方案2】:

    你不能不使用它会实现的一些技巧

    打开您的 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

    【讨论】:

      猜你喜欢
      • 2021-10-17
      • 2019-12-26
      • 2022-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-12
      相关资源
      最近更新 更多