zoukankan      html  css  js  c++  java
  • 呼吸灯

    吸吸灯动绘完成便是设置元件的通明度从无到有不停轮回。 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"];

    挥毫泼墨,书写人生篇章
  • 相关阅读:
    Leetcode86.分隔链表
    Leetcode39.组合总和
    Leetcode31.下一个排列
    剑指Offer35.复杂链表复制
    剑指Offer14-I.剪绳子
    剑指Offer38.字符串的排序
    Leetcode29.两数相除
    232. Implement Queue using Stacks
    程序员跳槽指南
    226. Invert Binary Tree
  • 原文地址:https://www.cnblogs.com/Jusive/p/6030682.html
Copyright © 2011-2022 走看看