Plane1Controller.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // Plane1Controller.m
  3. // animatedemo
  4. //
  5. // Created by 7yword on 16/7/11.
  6. // Copyright © 2016年 7yworld. All rights reserved.
  7. //
  8. #import "Plane1Controller.h"
  9. #define a_duration 2.0f
  10. @interface Plane1Controller ()
  11. @property (weak, nonatomic) IBOutlet UIView *contrainerView;
  12. @property (weak, nonatomic) IBOutlet UIImageView *wing1;
  13. @property (weak, nonatomic) IBOutlet UIImageView *wing2;
  14. @property (weak, nonatomic) IBOutlet UIImageView *wing3;
  15. @property (weak, nonatomic) IBOutlet UIImageView *wing4;
  16. @end
  17. @implementation Plane1Controller
  18. - (void)viewDidLoad
  19. {
  20. [super viewDidLoad];
  21. self.view.backgroundColor = kClearColor;
  22. _contrainerView.hidden = YES;
  23. [self.view bringSubviewToFront:_contrainerView];
  24. _senderNameLabel.textColor = kTextColorSenderName;
  25. _senderNameLabel.text = _senderNameStr;
  26. [self do_rotation:_wing1];
  27. [self do_rotation:_wing2];
  28. [self do_rotation:_wing3];
  29. [self do_rotation:_wing4];
  30. __weak typeof(self) weakSelf = self;
  31. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(a_duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  32. weakSelf.contrainerView.hidden = NO;
  33. [weakSelf do_move:_contrainerView];
  34. });
  35. }
  36. #pragma mark - 旋转动画
  37. - (void)do_rotation:(UIView *)view
  38. {
  39. CABasicAnimation* rotationAnimation;
  40. rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
  41. rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 1.0];
  42. rotationAnimation.duration = 0.2f;
  43. rotationAnimation.cumulative = YES;
  44. rotationAnimation.repeatCount = INT_MAX;
  45. [view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
  46. }
  47. #pragma mark - 平移动画
  48. - (void)do_move:(UIView *)view
  49. {
  50. CABasicAnimation * moveAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
  51. moveAnimation.fromValue = [NSValue valueWithCGPoint:CGPointMake(kScreenW, 0)];
  52. moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(kScreenW / 2.0f, kScreenH / 2.0f)];
  53. moveAnimation.duration = 3.0f;
  54. moveAnimation.removedOnCompletion = NO;
  55. moveAnimation.repeatCount = 1;
  56. moveAnimation.delegate = self;
  57. moveAnimation.fillMode = kCAFillModeForwards;
  58. [moveAnimation setValue:@"moveAnimation" forKey:@"moveAnimation"];
  59. [view.layer addAnimation:moveAnimation forKey:@"moveAnimation"];
  60. }
  61. - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
  62. {
  63. NSString * value = [anim valueForKey:@"moveAnimation"];
  64. if ([value isEqualToString:@"moveAnimation"])
  65. {
  66. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  67. CABasicAnimation * moveAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
  68. moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(0, [[UIScreen mainScreen] bounds].size.height + 50)];
  69. moveAnimation.duration = 3.0f;
  70. moveAnimation.removedOnCompletion = NO;
  71. moveAnimation.repeatCount = 1;
  72. moveAnimation.delegate = self;
  73. moveAnimation.fillMode = kCAFillModeForwards;
  74. [moveAnimation setValue:@"moveAnimation1" forKey:@"moveAnimation1"];
  75. [_contrainerView.layer addAnimation:moveAnimation forKey:@"moveAnimation1"];
  76. });
  77. }
  78. else if([[anim valueForKey:@"moveAnimation1"] isEqualToString:@"moveAnimation1"])
  79. {
  80. [_contrainerView setHidden:YES];
  81. if (_delegate && [_delegate respondsToSelector:@selector(plane1AnimationFinished)])
  82. {
  83. [_delegate plane1AnimationFinished];
  84. [self.view removeFromSuperview];
  85. }
  86. }
  87. }
  88. - (void)updateViewConstraints
  89. {
  90. [super updateViewConstraints];
  91. }
  92. @end