#import "ViewController.h" @interface ViewController () @property (nonatomic,strong) UIImageView *imageView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [self.view addSubview:self.imageView]; } - (UIImageView *)imageView { if (! _imageView) { _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; _imageView.layer.cornerRadius = 100; _imageView.layer.masksToBounds = YES; _imageView.center = self.view.center; _imageView.image = [UIImage imageNamed:@"zrx4.jpg"]; CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; animation.duration = 10; animation.fromValue = [NSNumber numberWithFloat:0.f]; animation.toValue = [NSNumber numberWithFloat: M_PI *2]; animation.autoreverses = NO; animation.fillMode = kCAFillModeForwards; animation.repeatCount = MAXFLOAT; [_imageView.layer addAnimation:animation forKey:nil]; } return _imageView; } @endCopy the code

#import "ViewController.h" @interface ViewController () @property (nonatomic,strong) UIImageView *imageView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [self.view addSubview:self.imageView]; // [self setUpAlphaAnimation]; // [self setUpSharkAnimation]; / / / / / pendulum effect [self setUpCAKeyframeAnimationUseValues]; / / / / / edge run laps effectiveness (self setUpCAKeyframeAnimationUsePath]; Rectangular line / / / / / [self setUpCAKeyframeAnimationUsekeyTimes]; /// move left/right [self setUpAnimationGroup]; } - (UIImageView *)imageView {if (! _imageView) { _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; _imageView.layer.cornerRadius = 100; _imageView.layer.masksToBounds = YES; _imageView.center = self.view.center; _imageView.image = [UIImage imageNamed:@"zrx4.jpg"]; } return _imageView; AnimationWithKeyPath :@" animationWithKeyPath "]; // animationwithanimationAnimationWithkeypath :@"opacity"];  Animation. FromValue = [NSNumber numberWithFloat: 1.0 f]; Animation. ToValue = [NSNumber numberWithFloat: 0.0 f]; animation.autoreverses = YES; Animation. duration = 1.0f; animation.repeatCount = MAXFLOAT; animation.removedOnCompletion = NO; animation.fillMode = kCAFillModeForwards; / / removedOnCompletion fillMode with use to keep animation complete animation effect. TimingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; [self.imageView.layer addAnimation:animation forKey:@"alpha"]; } / / / pendulum effect - (void) setUpSharkAnimation {/ / set rotation origin self. ImageView. Layer. The anchorPoint = CGPointMake (0.5, 0); CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; / / Angle radian (here with 1, 1, simple processing) rotationAnimation. ToValue = [NSNumber numberWithFloat: 1); rotationAnimation.fromValue = [NSNumber numberWithFloat:-1]; RotationAnimation. Duration = 1.0 f; rotationAnimation.repeatCount = MAXFLOAT; rotationAnimation.removedOnCompletion = NO; rotationAnimation.autoreverses = YES; rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; rotationAnimation.fillMode = kCAFillModeForwards; [self.imageView.layer addAnimation:rotationAnimation forKey:@"shark"]; } / / / edge effect of run laps - (void) setUpCAKeyframeAnimationUseValues {CAKeyframeAnimation * animation = [CAKeyframeAnimation animation]; animation.keyPath = @"position"; NSValue *value1 = [NSValue valueWithCGPoint:CGPointMake(50, 50)]; NSValue *value2 = [NSValue valueWithCGPoint:CGPointMake([UIScreen mainScreen].bounds.size.width - 50, 50)]; NSValue *value3 = [NSValue valueWithCGPoint:CGPointMake([UIScreen mainScreen].bounds.size.width - 50, [UIScreen mainScreen].bounds.size.height-50)]; NSValue *value4 = [NSValue valueWithCGPoint:CGPointMake(50, [UIScreen mainScreen].bounds.size.height-50)]; NSValue *value5 = [NSValue valueWithCGPoint:CGPointMake(50, 50)]; animation.values = @[value1,value2,value3,value4,value5]; animation.repeatCount = MAXFLOAT; animation.removedOnCompletion = NO; animation.fillMode = kCAFillModeForwards; Animation. Duration = 6.0 f; animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; [self.imageView.layer addAnimation:animation forKey:@"values"]; } / / / rectangular lines - (void) setUpCAKeyframeAnimationUsePath {CAKeyframeAnimation * animation = [CAKeyframeAnimation animation]; animation.keyPath = @"position"; CGMutablePathRef path = CGPathCreateMutable(); CGPathAddRect(path, NULL, CGRectMake(50,50, [UIScreen mainScreen].bounds.size.width - 100,[UIScreen mainScreen].bounds.size.height - 100)); animation.path = path; CGPathRelease(path); animation.repeatCount = MAXFLOAT; animation.removedOnCompletion = NO; animation.fillMode = kCAFillModeForwards; Animation. Duration = 6.0 f; animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; [self.imageView.layer addAnimation:animation forKey:@"path"]; } / / / move effect - (void) setUpCAKeyframeAnimationUsekeyTimes {CAKeyframeAnimation * animation = [CAKeyframeAnimation animation]; animation.keyPath = @"position.x"; animation.values = @[@0, @20, @-20, @20, @0]; Animation. KeyTimes = @ [@ 0, @ (1/6.0), @ (3/6.0), @ (5/6.0), @ 1]; animation.duration = 5; animation.additive = YES; [self.imageView.layer addAnimation:animation forKey:@"keyTimes"]; } setUpAnimationGroup {CABasicAnimation * animationScale = [CABasicAnimation animation]; animationScale.keyPath = @"transform.scale"; AnimationScale. ToValue = @ (0.1); CABasicAnimation *animationRota = [CABasicAnimation animation]; animationRota.keyPath = @"transform.rotation"; animationRota.toValue = @(M_PI_2); CAAnimationGroup * group = [[CAAnimationGroup alloc] init]; Group. The duration = 3.0; group.fillMode = kCAFillModeForwards; group.removedOnCompletion = NO; group.repeatCount = MAXFLOAT; group.animations = @[animationScale,animationRota]; [self.imageView.layer addAnimation:group forKey:nil]; } @endCopy the code