美文网首页
iOS给控件添加动画

iOS给控件添加动画

作者: 倒着游的鱼 | 来源:发表于2021-03-17 11:05 被阅读0次

    删除类似的晃动

    
    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"];
    
    

    左右晃动

    
    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];
    
    

    相关文章

      网友评论

          本文标题:iOS给控件添加动画

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