Plane2Controller.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // Plane2Controller.m
  3. // animatedemo
  4. //
  5. // Created by 7yword on 16/7/11.
  6. // Copyright © 2016年 7yworld. All rights reserved.
  7. //
  8. #import "Plane2Controller.h"
  9. #define a_duration 2.0f
  10. @interface Plane2Controller ()
  11. @property (weak, nonatomic) IBOutlet UIImageView *planeImgView;
  12. @property (weak, nonatomic) IBOutlet UIImageView *y1;
  13. @property (weak, nonatomic) IBOutlet UIImageView *y2;
  14. @property (weak, nonatomic) IBOutlet UIImageView *y3;
  15. @property (weak, nonatomic) IBOutlet UIImageView *y4;
  16. @property (weak, nonatomic) IBOutlet UIView *moveable;
  17. @end
  18. @implementation Plane2Controller
  19. - (void)viewDidLoad
  20. {
  21. [super viewDidLoad];
  22. self.view.backgroundColor = kClearColor;
  23. _contrainerView.hidden = YES;
  24. [self.view bringSubviewToFront:_contrainerView];
  25. _senderNameLabel.textColor = kTextColorSenderName;
  26. _senderNameLabel.text = _senderNameStr;
  27. [self do_up:nil withView:_moveable];
  28. __weak typeof(self) weakSelf = self;
  29. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(a_duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  30. weakSelf.contrainerView.hidden = NO;
  31. [weakSelf do_move:_contrainerView];
  32. });
  33. }
  34. #pragma mark - 云朵上移
  35. - (void)do_up:(NSLayoutConstraint *)constraint withView:(UIView *)view
  36. {
  37. CABasicAnimation * moveAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
  38. moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake([[UIScreen mainScreen] bounds].size.width / 2, [[UIScreen mainScreen] bounds].size.height / 2)];
  39. moveAnimation.duration = a_duration;
  40. moveAnimation.removedOnCompletion = NO;
  41. moveAnimation.repeatCount = 1;
  42. moveAnimation.fillMode = kCAFillModeForwards;
  43. [moveAnimation setValue:@"moveAnimation1" forKey:@"moveAnimation1"];
  44. [view.layer addAnimation:moveAnimation forKey:@"moveAnimation1"];
  45. }
  46. #pragma mark - 平移动画
  47. - (void)do_move:(UIView *)view
  48. {
  49. CABasicAnimation * moveAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
  50. moveAnimation.fromValue = [NSValue valueWithCGPoint:CGPointMake(kScreenW, 0)];
  51. moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake([[UIScreen mainScreen] bounds].size.width / 2.0f, [[UIScreen mainScreen] bounds].size.height / 2.0f)];
  52. moveAnimation.duration = 3.0f;
  53. moveAnimation.removedOnCompletion = NO;
  54. moveAnimation.repeatCount = 1;
  55. moveAnimation.delegate = self;
  56. moveAnimation.fillMode = kCAFillModeForwards;
  57. [moveAnimation setValue:@"moveAnimation" forKey:@"moveAnimation"];
  58. [view.layer addAnimation:moveAnimation forKey:@"moveAnimation"];
  59. _planeImgView.animationImages = @[[UIImage imageNamed:@"fw_gift_aircraft3"],[UIImage imageNamed:@"fw_gift_aircraft2"]];
  60. _planeImgView.animationDuration = 0.8f;
  61. _planeImgView.animationRepeatCount = INT_MAX;
  62. [_planeImgView startAnimating];
  63. }
  64. - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
  65. {
  66. NSString * value = [anim valueForKey:@"moveAnimation"];
  67. if ([value isEqualToString:@"moveAnimation"])
  68. {
  69. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  70. CABasicAnimation * moveAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
  71. moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(0, [[UIScreen mainScreen] bounds].size.height + 50)];
  72. moveAnimation.duration = 3.0f;
  73. moveAnimation.removedOnCompletion = NO;
  74. moveAnimation.repeatCount = 1;
  75. moveAnimation.delegate = self;
  76. moveAnimation.fillMode = kCAFillModeForwards;
  77. [moveAnimation setValue:@"moveAnimation1" forKey:@"moveAnimation1"];
  78. [_contrainerView.layer addAnimation:moveAnimation forKey:@"moveAnimation1"];
  79. });
  80. }
  81. else if([[anim valueForKey:@"moveAnimation1"] isEqualToString:@"moveAnimation1"])
  82. {
  83. [_contrainerView setHidden:YES];
  84. if (_delegate && [_delegate respondsToSelector:@selector(plane2AnimationFinished)])
  85. {
  86. [_delegate plane2AnimationFinished];
  87. [self.view removeFromSuperview];
  88. }
  89. }
  90. }
  91. - (void)updateViewConstraints
  92. {
  93. [super updateViewConstraints];
  94. }
  95. @end