UIImageView+FBRotation.m 963 B

123456789101112131415161718192021222324252627282930313233
  1. //
  2. // UIImageView+FBRotation.m
  3. // HappyJob
  4. //
  5. // Created by Bob on 2019/4/29.
  6. // Copyright © 2019 Bob. All rights reserved.
  7. //
  8. #import "UIImageView+FBRotation.h"
  9. @implementation UIImageView (FBRotation)
  10. - (void)fb_startAnimation {
  11. CGFloat speed = 1.0;
  12. [self fb_startAnimationWithSpeed:speed];
  13. }
  14. - (void)fb_startAnimationWithSpeed:(CGFloat)speed {
  15. CABasicAnimation *rotationAnimation;
  16. rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
  17. // 默认是逆时针效果,若将fromValue和toValue的值互换,则为顺时针效果
  18. rotationAnimation.fromValue = [NSNumber numberWithFloat:M_PI*speed];
  19. rotationAnimation.toValue = [NSNumber numberWithFloat:0.f];
  20. rotationAnimation.duration = 1;
  21. rotationAnimation.repeatCount = HUGE_VALF;
  22. [self.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
  23. }
  24. - (void)fb_stopAnimation {
  25. [self.layer removeAllAnimations];
  26. }
  27. @end