iOS开发- 启动动画(动态欢迎界面,非静态Default)

本文介绍了一种在iOS应用启动时实现动态启动页的方法。通过在AppDelegate中添加自定义动画,可以在应用完全启动前展示一系列渐进动画效果,提升用户体验。文章提供了具体的代码示例,包括如何设置UIImageView来显示背景图片及动画元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://blog.youkuaiyun.com/hitwhylz/article/details/19079549


最近在使用《青葱日记》这款App,发现它的启动界面做的很精美。

不同我自己之前简单的替换Default.png图片。 它的动态效果做的不错。

于是乎,花了点时间,自己实现了这个功能。 其实也很简单,具体效果如下




实现起来也不困难。因为我们知道,在应用启动的时候,它会先执行AppDelegate.m中的

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  

执行完之后,才会进入视图。如果,我们在这个方法中加入一些动画,那么就会在动画执行完之后再进入我们的rootview。这就是实现原理。 很简单吧。


下面直接给出实现这一效果的源码,很简单。不多说废话(当然,实现方法很多。 我只是给出我自己的方法)


1.AppDelegate.h中声明一个UIImageView

@property (strong, nonatomic) UIImageView *splashView;

2.AppDelegate.m实现相关功能

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. @synthesize splashView;  
  2. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  3. {  
  4.     // Override point for customization after application launch.  
  5.     [self.window makeKeyAndVisible];  
  6.       
  7.     splashView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];  
  8.     [splashView setImage:[UIImage imageNamed:@"back_"]];  
  9.       
  10.     [self.window addSubview:splashView];  
  11.     [self.window bringSubviewToFront:splashView];  
  12.       
  13.       
  14.     [self performSelector:@selector(scale_1) withObject:nil afterDelay:0.0f];  
  15.     [self performSelector:@selector(scale_2) withObject:nil afterDelay:0.5f];  
  16.     [self performSelector:@selector(scale_3) withObject:nil afterDelay:1.0f];  
  17.     [self performSelector:@selector(scale_4) withObject:nil afterDelay:1.5f];  
  18.     [self performSelector:@selector(scale_5) withObject:nil afterDelay:2.0f];  
  19.     [self performSelector:@selector(showWord) withObject:nil afterDelay:2.5f];  
  20.   
  21.       
  22.     return YES;  
  23. }  
  24.   
  25. -(void)scale_1  
  26. {  
  27.     UIImageView *round_1 = [[UIImageView alloc]initWithFrame:CGRectMake(100, 240, 15, 15)];  
  28.     round_1.image = [UIImage imageNamed:@"round_"];  
  29.     [splashView addSubview:round_1];  
  30.     [self setAnimation:round_1];  
  31. }  
  32.   
  33. -(void)scale_2  
  34. {  
  35.     UIImageView *round_2 = [[UIImageView alloc]initWithFrame:CGRectMake(105, 210, 20, 20)];  
  36.     round_2.image = [UIImage imageNamed:@"round_"];  
  37.     [splashView addSubview:round_2];  
  38.     [self setAnimation:round_2];  
  39. }  
  40.   
  41. -(void)scale_3  
  42. {  
  43.     UIImageView *round_3 = [[UIImageView alloc]initWithFrame:CGRectMake(125, 170, 30, 30)];  
  44.     round_3.image = [UIImage imageNamed:@"round_"];  
  45.     [splashView addSubview:round_3];  
  46.     [self setAnimation:round_3];  
  47. }  
  48.   
  49. -(void)scale_4  
  50. {  
  51.     UIImageView *round_4 = [[UIImageView alloc]initWithFrame:CGRectMake(160, 135, 40, 40)];  
  52.     round_4.image = [UIImage imageNamed:@"round_"];  
  53.     [splashView addSubview:round_4];  
  54.     [self setAnimation:round_4];  
  55. }  
  56.   
  57. -(void)scale_5  
  58. {  
  59.     UIImageView *heart_1 = [[UIImageView alloc]initWithFrame:CGRectMake(130, 180, 100, 100)];  
  60.     heart_1.image = [UIImage imageNamed:@"heart_"];  
  61.     [splashView addSubview:heart_1];  
  62.     [self setAnimation:heart_1];  
  63. }  
  64.   
  65. -(void)setAnimation:(UIImageView *)nowView  
  66. {  
  67.       
  68.     [UIView animateWithDuration:0.6f delay:0.0f options:UIViewAnimationOptionCurveLinear  
  69.                      animations:^  
  70.                     {  
  71.                         // 执行的动画code  
  72.                         [nowView setFrame:CGRectMake(nowView.frame.origin.x- nowView.frame.size.width*0.1, nowView.frame.origin.y-nowView.frame.size.height*0.1, nowView.frame.size.width*1.2, nowView.frame.size.height*1.2)];  
  73.                      }  
  74.                      completion:^(BOOL finished)  
  75.                     {  
  76.                          // 完成后执行code  
  77.                         [nowView removeFromSuperview];  
  78.                      }  
  79.      ];  
  80.       
  81.   
  82. }  
  83.   
  84. -(void)showWord  
  85. {  
  86.       
  87.     UIImageView *word_ = [[UIImageView alloc]initWithFrame:CGRectMake(75, 440, 170, 29)];  
  88.     word_.image = [UIImage imageNamed:@"word_"];  
  89.     [splashView addSubview:word_];  
  90.       
  91.     word_.alpha = 0.0;  
  92.     [UIView animateWithDuration:1.0f delay:0.0f options:UIViewAnimationOptionCurveLinear  
  93.                      animations:^  
  94.                      {  
  95.                          word_.alpha = 1.0;  
  96.                      }  
  97.                      completion:^(BOOL finished)  
  98.                      {  
  99.                          // 完成后执行code  
  100.                          [NSThread sleepForTimeInterval:1.0f];  
  101.                          [splashView removeFromSuperview];  
  102.                      }  
  103.      ];  
  104. }  

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值