iOS启动屏动画

5
在我的应用程序中,我希望启动画面能够动画显示。我使用了以下代码,但是动画没有生效。
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");
                }
];

你想要一个启动画面吗?为什么这么复杂呢? - chandru
你的默认屏幕美观动人,让我想要停留更久吗?我表示怀疑。我宁愿在应用程序准备好后立即开始使用它。大多数人也是如此。 - Abizern
你在哪里使用了这段代码?是在rootViewController的viewDidLoad方法中还是其他地方? - channi
本文介绍了一些更具动态性的启动屏幕的可能性:http://blog.hawkimedia.com/2014/10/dynamic-interactive-launch-screens/ - Bjørn Egil
2个回答

7

您无法对闪屏图像进行动画处理,但是您可以等待应用启动后添加具有动画效果的自定义视图。


6

您必须使用一些技巧才能实现

打开您的AppDelegate.m文件,将以下代码添加到您的应用程序didFinishLaunching或application 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];
                 }];

下载示例应用程序

动画启动屏幕默认PNG


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接