抖动效果

作者: 小破孩丫 | 来源:发表于2016-01-25 11:28 被阅读43次

/**

*  抖动效果

*

*  @param view 要抖动的view

*/

- (void)shakeAnimationForView:(UIView *) view {

CALayer *viewLayer = view.layer;

CGPoint position = viewLayer.position;

CGPoint x = CGPointMake(position.x + 1, position.y);

CGPoint y = CGPointMake(position.x - 1, position.y);

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

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];

[animation setFromValue:[NSValue valueWithCGPoint:x]];

[animation setToValue:[NSValue valueWithCGPoint:y]];

[animation setAutoreverses:YES];

[animation setDuration:.06];

[animation setRepeatCount:3];

[viewLayer addAnimation:animation forKey:nil];

}

相关文章

网友评论

    本文标题:抖动效果

    本文链接:https://www.haomeiwen.com/subject/lvzrkttx.html