美文网首页
view摇晃效果

view摇晃效果

作者: 陈水寒 | 来源:发表于2016-12-12 10:53 被阅读15次
    // 摇晃效果
    - (void)shakeAnimationForView:(UIView *)view
    {
        CALayer *viewLayer = view.layer;
        CGPoint position = viewLayer.position;
        CGPoint left = CGPointMake(position.x - 10, position.y);
        CGPoint right = CGPointMake(position.x + 10, position.y);
        
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
        [animation setFromValue:[NSValue valueWithCGPoint:left]];
        [animation setToValue:[NSValue valueWithCGPoint:right]];
        [animation setAutoreverses:YES];
        [animation setDuration:0.08];
        [animation setRepeatCount:3];
        [viewLayer addAnimation:animation forKey:nil];
    }
    

    相关文章

      网友评论

          本文标题:view摇晃效果

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