左右晃动
```
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"];
```
网友评论