• 呼吸灯


    吸吸灯动绘完成便是设置元件的通明度从无到有不停轮回。 2.代码完成 #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) ]

    1.思路:呼吸灯动画实现就是设置元件的透明度从无到有一直循环。

    2.代码实现

    #import "ViewController.h"

    @interface ViewController ()

    @property (weak, nonatomic) IBOutlet UIView *myView;

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        _myView.layer.cornerRadius = 8;

    //添加动画效果,aAlpha是给此次动画添加的标识,方便我们删除动画时,根据这个标识删除。

        [_myView.layer addAnimation:[self alphaLight:0.5] forKey:@"aAlpha"];

    }

    #pragma mark - 呼吸灯动画

    -(CABasicAnimation *)alphaLight:(float)time

    {

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

        animation.fromValue = [NSNumber numberWithFloat:1.0f];

        animation.toValue = [NSNumber numberWithFloat:0.3f];//这是透明度。

        animation.autoreverses = YES;

        animation.duration = time;

        animation.repeatCount = MAXFLOAT;

        animation.removedOnCompletion = NO;

        animation.fillMode = kCAFillModeForwards;

        animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

        return animation;

    }

    3.移除动画

    [_myView.layer removeAnimationForKey:@"aAlpha"];

    挥毫泼墨,书写人生篇章
  • 相关阅读:
    AUTOSAR-文档中所使用的UML文件
    开心一下-实现基于Java一个中文编程语言
    HDU 1026 Ignatius and the Princess I
    HDU 2553 (状压) N皇后问题 (2)
    UVa 11825 (状压DP) Hackers' Crackdown
    UVa 10891 (博弈+DP) Game of Sum
    LA 2965 Jurassic Remains
    HDU 2126 (背包方法数) Buy the souvenirs
    POJ 3984 迷宫问题
    POJ 3287 (基础BFS) Catch That Cow
  • 原文地址:https://www.cnblogs.com/Jusive/p/6030682.html
Copyright © 2020-2023  润新知