CarRefreshHeadView.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //
  2. // CarRefreshHeadView.m
  3. // HaoChe-App-iOS
  4. //
  5. // Created by Sunyi on 16/10/19.
  6. // Copyright © 2016年 Fuzhou Qiankunhaoche E-commerce Technology. All rights reserved.
  7. //
  8. #import "CarRefreshHeadView.h"
  9. #import "XTSystem.h"
  10. @interface CarRefreshHeadView ()
  11. @property (nonatomic, strong) UIView *centerView;
  12. @end
  13. @implementation CarRefreshHeadView
  14. /*
  15. // Only override drawRect: if you perform custom drawing.
  16. // An empty implementation adversely affects performance during animation.
  17. - (void)drawRect:(CGRect)rect {
  18. // Drawing code
  19. }
  20. */
  21. //- (void)startAnimation{
  22. // [self startAnimationCarRefreshBackgroundType:kCarRefreshBackgroundTypeBlack];
  23. //}
  24. - (void)startAnimationCarRefreshBackgroundType:(CarRefreshBackgroundType)groundType{
  25. CABasicAnimation* rotationAnimation;
  26. rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
  27. rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
  28. rotationAnimation.duration = 1;
  29. rotationAnimation.cumulative = YES;
  30. rotationAnimation.repeatCount = NSIntegerMax;
  31. rotationAnimation.removedOnCompletion = NO;
  32. [self.mj_OneShoeView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
  33. [self.mj_TowShoeView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation1"];
  34. CABasicAnimation* rotationAnimation2;
  35. rotationAnimation2 = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
  36. rotationAnimation2.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
  37. rotationAnimation2.duration = 3;
  38. rotationAnimation2.cumulative = YES;
  39. rotationAnimation2.repeatCount = NSIntegerMax;
  40. rotationAnimation2.removedOnCompletion = NO;
  41. switch (groundType) {
  42. case kCarRefreshBackgroundTypeBlack:{
  43. [self.mj_SunView setImage:[UIImage imageNamed:@"mj_sun"]];
  44. [self.mj_AirView setImage:[UIImage imageNamed:@"mj_air"]];
  45. }break;
  46. case kCarRefreshBackgroundTypeWhite:{
  47. [self.mj_SunView setImage:[UIImage imageNamed:@"mj_sun_black"]];
  48. [self.mj_AirView setImage:[UIImage imageNamed:@"mj_air_black"]];
  49. }break;
  50. default:
  51. break;
  52. }
  53. [self.mj_SunView.layer addAnimation:rotationAnimation2 forKey:@"rotationAnimation2"];
  54. if (self.centerView == nil) {
  55. self.centerView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2 - 70, 42/2 - 8, 142, 25)];
  56. [self.centerView setClipsToBounds:YES];
  57. [self.centerView setBackgroundColor:[UIColor clearColor]];
  58. [self insertSubview:self.centerView atIndex:0];
  59. switch (groundType) {
  60. case kCarRefreshBackgroundTypeBlack:{
  61. self.mj_HouseView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mj_house"]];
  62. [self.mj_HouseView setFrame:CGRectMake(0, 0, 142, 25)];
  63. [self.centerView addSubview:self.mj_HouseView];
  64. self.mj_HouseView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mj_house"]];
  65. [self.mj_HouseView1 setFrame:CGRectMake(142, 0, 142, 25)];
  66. [self.centerView addSubview:self.mj_HouseView1];
  67. }break;
  68. case kCarRefreshBackgroundTypeWhite:{
  69. self.mj_HouseView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mj_house_black"]];
  70. [self.mj_HouseView setFrame:CGRectMake(0, 0, 142, 25)];
  71. [self.centerView addSubview:self.mj_HouseView];
  72. self.mj_HouseView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mj_house_black"]];
  73. [self.mj_HouseView1 setFrame:CGRectMake(142, 0, 142, 25)];
  74. [self.centerView addSubview:self.mj_HouseView1];
  75. }break;
  76. default:
  77. break;
  78. }
  79. }
  80. CABasicAnimation *animation =
  81. [CABasicAnimation animationWithKeyPath:@"position"];
  82. animation.duration = 3; // 动画持续时间
  83. animation.repeatCount = NSIntegerMax; // 不重复
  84. animation.autoreverses = NO; // 结束后执行逆动画
  85. animation.removedOnCompletion = NO;
  86. if([XTSystem isPhoneRetina35] || [XTSystem isPhoneRetina4]){
  87. animation.fromValue = [NSValue valueWithCGPoint:CGPointMake(SCREEN_WIDTH/2 - self.centerView.frame.size.width/2 - 30, 12)]; // 起始点
  88. animation.toValue = [NSValue valueWithCGPoint:CGPointMake(SCREEN_WIDTH/2 - self.mj_HouseView.frame.size.width/2 - self.mj_HouseView.frame.size.width - 30, 12)];
  89. }
  90. if([XTSystem isPhoneRetina6]){
  91. animation.fromValue = [NSValue valueWithCGPoint:CGPointMake(SCREEN_WIDTH/2 - self.centerView.frame.size.width/2 - 45, 12)]; // 起始点
  92. animation.toValue = [NSValue valueWithCGPoint:CGPointMake(SCREEN_WIDTH/2 - self.mj_HouseView.frame.size.width/2 - self.mj_HouseView.frame.size.width - 45, 12)];
  93. }
  94. if([XTSystem isPhoneRetina6Plus]){
  95. animation.fromValue = [NSValue valueWithCGPoint:CGPointMake(SCREEN_WIDTH/2 - self.centerView.frame.size.width/2 - 60, 12)]; // 起始点
  96. animation.toValue = [NSValue valueWithCGPoint:CGPointMake(SCREEN_WIDTH/2 - self.mj_HouseView.frame.size.width/2 - self.mj_HouseView.frame.size.width - 60, 12)];
  97. }
  98. [self.mj_HouseView.layer addAnimation:animation forKey:@"rotate-layer"];
  99. CABasicAnimation *animation1 =
  100. [CABasicAnimation animationWithKeyPath:@"position"];
  101. animation1.duration = 3; // 动画持续时间
  102. animation1.repeatCount = NSIntegerMax; // 不重复
  103. animation1.autoreverses = NO; // 结束后执行逆动画
  104. animation1.removedOnCompletion = NO;
  105. if([XTSystem isPhoneRetina35] || [XTSystem isPhoneRetina4]){
  106. animation1.fromValue = [NSValue valueWithCGPoint:CGPointMake(SCREEN_WIDTH/2 + self.mj_HouseView1.frame.size.width/2 - 30 , 12)]; // 起始点
  107. animation1.toValue = [NSValue valueWithCGPoint:CGPointMake(SCREEN_WIDTH/2 - self.mj_HouseView1.frame.size.width/2 - 30, 12)];
  108. }
  109. if([XTSystem isPhoneRetina6]){
  110. animation1.fromValue = [NSValue valueWithCGPoint:CGPointMake(SCREEN_WIDTH/2 + self.mj_HouseView1.frame.size.width/2 - 45 , 12)]; // 起始点
  111. animation1.toValue = [NSValue valueWithCGPoint:CGPointMake(SCREEN_WIDTH/2 - self.mj_HouseView1.frame.size.width/2 - 45, 12)];
  112. }
  113. if([XTSystem isPhoneRetina6Plus]){
  114. animation1.fromValue = [NSValue valueWithCGPoint:CGPointMake(SCREEN_WIDTH/2 + self.mj_HouseView1.frame.size.width/2 - 60 , 12)]; // 起始点
  115. animation1.toValue = [NSValue valueWithCGPoint:CGPointMake(SCREEN_WIDTH/2 - self.mj_HouseView1.frame.size.width/2 - 60, 12)];
  116. }
  117. [self.mj_HouseView1.layer addAnimation:animation1 forKey:@"rotate-layer1"];
  118. CABasicAnimation *animationScale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  119. // 动画选项设定
  120. animationScale.duration = 2; // 动画持续时间
  121. animationScale.repeatCount = NSIntegerMax; // 重复次数
  122. animationScale.fromValue = [NSNumber numberWithFloat:0.4]; // 开始时的倍率
  123. animationScale.toValue = [NSNumber numberWithFloat:1]; // 结束时的倍率
  124. animationScale.removedOnCompletion = NO;
  125. // 添加动画
  126. [self.mj_AirView.layer addAnimation:animationScale forKey:@"scale-layer"];
  127. /* 移动 */
  128. CABasicAnimation *animation3 = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
  129. // 起止点的设定
  130. animation3.duration = 2; // 动画持续时间
  131. animation3.toValue = [NSNumber numberWithFloat: - 5];; // 終点
  132. animation3.repeatCount = NSIntegerMax; // 重复次数
  133. animation3.removedOnCompletion = NO;
  134. [self.mj_AirView.layer addAnimation:animation3 forKey:@"move-layer"];
  135. CABasicAnimation *animation4 = [CABasicAnimation animationWithKeyPath:@"opacity"];
  136. animation4.duration = 2; // 动画持续时间
  137. animation4.fromValue = [NSNumber numberWithFloat:1.0];
  138. animation4.toValue = [NSNumber numberWithFloat:0.0];
  139. animation4.repeatCount = NSIntegerMax; // 重复次数
  140. animation4.removedOnCompletion = NO;
  141. [self.mj_AirView.layer addAnimation:animation4 forKey:@"opacity-layer"];
  142. }
  143. @end