美文网首页
iOS动画,左右晃动、苹果删除抖动效果

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

作者: 司徒新新 | 来源:发表于2017-05-17 17:00 被阅读843次

    左右晃动

    ```

    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动画,左右晃动、苹果删除抖动效果

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