//联系人:石虎 QQ:1224614774 昵称:嗡嘛呢叭咪哄
一、概念
/**
1.此方法很简单,有操作视图和方法,动画效果参考~直接拷贝就可以实现
2. 图片下面有, 代码可以任意修改变化不同的颜色显示,
3.GIF 图请看CSDN:http://blog.csdn.net/shihuboke/article/details/79136364
*/
GIF图:
iPhone X

二、代码实现
// ViewController.m
// 滑动解锁动画~demo
//
// Created by joyshow on 2018/1/20.
// Copyright © 2018年 石虎. All rights reserved.
//
#import "ViewController.h"
#define SHPageCount 2
#define KMainScreenH [UIScreen mainScreen].bounds.size.height
#define kMainScreenW [UIScreen mainScreen].bounds.size.width
@interface ViewController ()
//解锁 label
@property (nonatomic,strong)UILabel *unlockLabel;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
[selfanimationUnlockLabel];
}
#pragma mark - 设置所有动画解锁方法
#pragma mark -
- (void)animationUnlockLabel
{
// gradientLayer
CAGradientLayer *gradientLayer = [CAGradientLayerlayer];
gradientLayer.frame = CGRectMake(0, 0, kMainScreenW, KMainScreenH);
gradientLayer.colors = @[(__bridge id)[UIColor redColor].CGColor,
(__bridge id)[UIColor yellowColor].CGColor,
(__bridge id)[UIColor purpleColor].CGColor];
gradientLayer.locations = @[@0.25,@0.5,@0.75];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1, 0);
[self.view.layeraddSublayer:gradientLayer];
// 初始化 unlockLabel
self.unlockLabel = [[UILabelalloc]initWithFrame:gradientLayer.bounds];
gradientLayer.mask = _unlockLabel.layer;
[self.viewaddSubview:_unlockLabel];
//执行动画 animation
CABasicAnimation *animation = [CABasicAnimationanimationWithKeyPath:@"locations"];
animation.fromValue = @[@0,@0,@0.25];
animation.toValue = @[@0.75,@1,@1];
animation.repeatCount = MAXFLOAT;
animation.duration = 2.5f;
[gradientLayer addAnimation:animation forKey:nil];
}
@end
网友评论