| 123456789101112131415161718192021222324252627282930313233 |
- //
- // UIImageView+FBRotation.m
- // HappyJob
- //
- // Created by Bob on 2019/4/29.
- // Copyright © 2019 Bob. All rights reserved.
- //
- #import "UIImageView+FBRotation.h"
- @implementation UIImageView (FBRotation)
- - (void)fb_startAnimation {
- CGFloat speed = 1.0;
- [self fb_startAnimationWithSpeed:speed];
- }
- - (void)fb_startAnimationWithSpeed:(CGFloat)speed {
- CABasicAnimation *rotationAnimation;
- rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
- // 默认是逆时针效果,若将fromValue和toValue的值互换,则为顺时针效果
- rotationAnimation.fromValue = [NSNumber numberWithFloat:M_PI*speed];
- rotationAnimation.toValue = [NSNumber numberWithFloat:0.f];
- rotationAnimation.duration = 1;
- rotationAnimation.repeatCount = HUGE_VALF;
- [self.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
- }
- - (void)fb_stopAnimation {
- [self.layer removeAllAnimations];
- }
- @end
|