当前位置:   article > 正文

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

动态启动 开发

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

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

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




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

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

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


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


1.AppDelegate.h中声明一个UIImageView

@property (strong, nonatomic) UIImageView *splashView;

2.AppDelegate.m实现相关功能

  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. splashView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
  7. [splashView setImage:[UIImage imageNamed:@"back_"]];
  8. [self.window addSubview:splashView];
  9. [self.window bringSubviewToFront:splashView];
  10. [self performSelector:@selector(scale_1) withObject:nil afterDelay:0.0f];
  11. [self performSelector:@selector(scale_2) withObject:nil afterDelay:0.5f];
  12. [self performSelector:@selector(scale_3) withObject:nil afterDelay:1.0f];
  13. [self performSelector:@selector(scale_4) withObject:nil afterDelay:1.5f];
  14. [self performSelector:@selector(scale_5) withObject:nil afterDelay:2.0f];
  15. [self performSelector:@selector(showWord) withObject:nil afterDelay:2.5f];
  16. return YES;
  17. }
  18. -(void)scale_1
  19. {
  20. UIImageView *round_1 = [[UIImageView alloc]initWithFrame:CGRectMake(100, 240, 15, 15)];
  21. round_1.image = [UIImage imageNamed:@"round_"];
  22. [splashView addSubview:round_1];
  23. [self setAnimation:round_1];
  24. }
  25. -(void)scale_2
  26. {
  27. UIImageView *round_2 = [[UIImageView alloc]initWithFrame:CGRectMake(105, 210, 20, 20)];
  28. round_2.image = [UIImage imageNamed:@"round_"];
  29. [splashView addSubview:round_2];
  30. [self setAnimation:round_2];
  31. }
  32. -(void)scale_3
  33. {
  34. UIImageView *round_3 = [[UIImageView alloc]initWithFrame:CGRectMake(125, 170, 30, 30)];
  35. round_3.image = [UIImage imageNamed:@"round_"];
  36. [splashView addSubview:round_3];
  37. [self setAnimation:round_3];
  38. }
  39. -(void)scale_4
  40. {
  41. UIImageView *round_4 = [[UIImageView alloc]initWithFrame:CGRectMake(160, 135, 40, 40)];
  42. round_4.image = [UIImage imageNamed:@"round_"];
  43. [splashView addSubview:round_4];
  44. [self setAnimation:round_4];
  45. }
  46. -(void)scale_5
  47. {
  48. UIImageView *heart_1 = [[UIImageView alloc]initWithFrame:CGRectMake(130, 180, 100, 100)];
  49. heart_1.image = [UIImage imageNamed:@"heart_"];
  50. [splashView addSubview:heart_1];
  51. [self setAnimation:heart_1];
  52. }
  53. -(void)setAnimation:(UIImageView *)nowView
  54. {
  55. [UIView animateWithDuration:0.6f delay:0.0f options:UIViewAnimationOptionCurveLinear
  56. animations:^
  57. {
  58. // 执行的动画code
  59. [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)];
  60. }
  61. completion:^(BOOL finished)
  62. {
  63. // 完成后执行code
  64. [nowView removeFromSuperview];
  65. }
  66. ];
  67. }
  68. -(void)showWord
  69. {
  70. UIImageView *word_ = [[UIImageView alloc]initWithFrame:CGRectMake(75, 440, 170, 29)];
  71. word_.image = [UIImage imageNamed:@"word_"];
  72. [splashView addSubview:word_];
  73. word_.alpha = 0.0;
  74. [UIView animateWithDuration:1.0f delay:0.0f options:UIViewAnimationOptionCurveLinear
  75. animations:^
  76. {
  77. word_.alpha = 1.0;
  78. }
  79. completion:^(BOOL finished)
  80. {
  81. // 完成后执行code
  82. [NSThread sleepForTimeInterval:1.0f];
  83. [splashView removeFromSuperview];
  84. }
  85. ];
  86. }


学习的路上,与君共勉。


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/248424
推荐阅读
相关标签
  

闽ICP备14008679号

        
cppcmd=keepalive&