函数代码: 有关CAGradientLayer知识见上篇文章
#pragma mark 字体动画 解锁
-(void)lableAnmation
{
self.backgroundColor=[UIColor grayColor];
CAGradientLayer *theGtradient=[CAGradientLayer layer];
theGtradient.frame=CGRectMake(0, 200, CGRectGetWidth(self.frame), 66);
[self.layer addSublayer:theGtradient];
theGtradient.colors=@[
(__bridge id)[UIColor blackColor].CGColor,
(__bridge id)[UIColor whiteColor].CGColor,
(__bridge id)[UIColor blackColor].CGColor
];
theGtradient.locations=@[@.25,@.5,@.75];
theGtradient.startPoint=CGPointMake(0, 0.5);
theGtradient.endPoint=CGPointMake(1., 0.5);
//动画
CABasicAnimation *theAnima=[CABasicAnimation animationWithKeyPath:@"locations"];
theAnima.fromValue=@[@0,@0,@0.25];
theAnima.toValue=@[@0.25,@1,@1];
theAnima.duration=2.5;
theAnima.repeatCount=HUGE;
[theGtradient addAnimation:theAnima forKey:@"locations"];
//uilable文字
UILabel *theUnlock=[[UILabel alloc]initWithFrame:theGtradient.bounds];
[self addSubview:theUnlock];
theUnlock.alpha=.5;
theUnlock.text=@"滑动解锁 >>";
theUnlock.textAlignment=NSTextAlignmentCenter;
theUnlock.font=[UIFont boldSystemFontOfSize:30];
theGtradient.mask=theUnlock.layer;
}
网友评论