iOS动画,左右晃动、苹果删除抖动效果

左右晃动

```

CALayer*viewLayer=[selflayer];

CGPointposition = viewLayer.position;

CGPointx =CGPointMake(position.x+3, position.y);

CGPointy =CGPointMake(position.x-3, position.y);

CABasicAnimation*animation = [CABasicAnimationanimationWithKeyPath:@"position"];

[animationsetTimingFunction:[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionDefault]];

[animationsetFromValue:[NSValuevalueWithCGPoint:x]];

[animationsetToValue:[NSValuevalueWithCGPoint:y]];

animation.duration=0.2;//持续时间

animation.repeatCount=5;//抖动次数

animation.autoreverses=YES;//反极性

[viewLayeraddAnimation:animationforKey:nil];

```

删除类似的晃动

```

CALayer*viewLayer=[selflayer];

CABasicAnimation*animation=[CABasicAnimationanimationWithKeyPath:@"transform"];

animation.duration=0.2;//持续时间

animation.repeatCount=5;//抖动次数

animation.autoreverses=YES;//反极性

animation.fromValue= [NSValuevalueWithCATransform3D:CATransform3DRotate(viewLayer.transform,-0.08,0.0,0.0,0.08)];

animation.toValue= [NSValuevalueWithCATransform3D:CATransform3DRotate(viewLayer.transform,0.08,0.0,0.0,0.08)];

[viewLayeraddAnimation:animationforKey:@"wiggle"];

```

你可能感兴趣的:(iOS动画,左右晃动、苹果删除抖动效果)