• Core Animation演示


    相关代码展示:

    - (IBAction)toggleRoundCorners:(id)sender {

        

        [CATransaction setDisableActions:![_enableAnimations isOn]];

        [CATransaction setAnimationDuration:_animationDuration];

        

        [_layer setCornerRadius:([_layer cornerRadius] == 0.0 ? 25.0 : 0.0)];

    }

    - (IBAction)toggleColor:(id)sender {

        [CATransaction setDisableActions:![_enableAnimations isOn]];

        [CATransaction setAnimationDuration:_animationDuration];

        

        [_layer setBackgroundColor:([_layer backgroundColor] == [UIColor blueColor].CGColor ? [UIColor greenColor].CGColor : [UIColor blueColor].CGColor)]; 

    }

    - (IBAction)toggleBorder:(id)sender {

        

        [CATransaction setDisableActions:![_enableAnimations isOn]];

        [CATransaction setAnimationDuration:_animationDuration];

        [_layer setBorderWidth:([_layer borderWidth] == 0.0 ? 10 : 0.0)];

    }

    - (IBAction)toggleOpacity:(id)sender {

        

        [CATransaction setDisableActions:![_enableAnimations isOn]];

        [CATransaction setAnimationDuration:_animationDuration];

        

        [_layer setOpacity:([_layer opacity] == 1.0 ? 0.2 : 1.0)];

    }

    - (IBAction)toggleSize:(id)sender 

    {

        [CATransaction setDisableActions:![_enableAnimations isOn]];

        [CATransaction setAnimationDuration:_animationDuration];

        

        CGRect layerBounds = _layer.bounds;

        layerBounds.size.width  = (layerBounds.size.width == layerBounds.size.height) ? 250.0 : 200.0;

        [_layer setBounds:layerBounds];

        

        BTSAnchorPointLayer *anchorPointLayer = [[_layer sublayers] objectAtIndex:0];

        [anchorPointLayer setPosition:BTSCalculateAnchorPointPositionForLayer(_layer)];

    }

    - (void)beginAnimatingLayer

    {

        // Here we are creating an explicit animation for the layer's "transform" property.

        // - The duration (in seconds) is controlled by the user.

        // - The repeat count is hard coded to go "forever".

        

        CABasicAnimation *pulseAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];

        [pulseAnimation setDuration:_animationDuration];

        [pulseAnimation setRepeatCount:MAXFLOAT];

        

        // The built-in ease in/ ease out timing function is used to make the animation look smooth as the layer

        // animates between the two scaling transformations.

        [pulseAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

        

        // Scale the layer to half the size

        CATransform3D transform = CATransform3DMakeScale(0.50, 0.50, 1.0);

        

        // Tell CA to interpolate to this transformation matrix

        [pulseAnimation setToValue:[NSValue valueWithCATransform3D:CATransform3DIdentity]];

        [pulseAnimation setToValue:[NSValue valueWithCATransform3D:transform]];

        

        // Tells CA to reverse the animation (e.g. animate back to the layer's transform)

        [pulseAnimation setAutoreverses:_autoreverses];

        

        // Finally... add the explicit animation to the layer... the animation automatically starts.

        [_layer addAnimation:pulseAnimation forKey:kBTSPulseAnimation];

    }

    - (void)endAnimatingLayer

    {

        [_layer removeAnimationForKey:kBTSPulseAnimation];

    }

  • 相关阅读:
    2021软工-提问回顾与个人总结
    2021软工-调研作业-Notion
    2021年软工-个人阅读作业2
    tester
    tableau学做两个集合的维恩图(文氏图)Venn diagram 二维文氏图
    python学习
    pv操作是否会造成死锁呢?
    提问的正确姿势
    【BUAA OO Unit3】史上最全OpenJML摸索实录
    MVC和三层架构的区别
  • 原文地址:https://www.cnblogs.com/yulang314/p/3833158.html
Copyright © 2020-2023  润新知