码迷,mamicode.com
首页 > 其他好文 > 详细

label字体闪烁效果

时间:2015-06-24 20:34:29      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

- (void)viewDidLoad {
[super viewDidLoad];
self.title = @" 测试动画 " ;
self.view.backgroundColor = [UIColor lightGrayColor];
_myTest1 = [[UILabel alloc]initWithFrame:CGRectMake( 10 , 100 , 60 , 40 )];
_myTest1.backgroundColor = [ UIColor clearColor];
_myTest1.textAlignment = NSTextAlignmentCenter ;
_myTest1.text = @" 张" ;
_myTest1.textColor = [ UIColor whiteColor ];
[ self.view addSubview:_myTest1 ];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.backgroundColor = [UIColor redColor];
btn.frame = CGRectMake(80, 180, 80, 80);
[btn addTarget:self action:@selector(removeAnimation) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)removeAnimation{
static int tag = 0;
if (tag == 0) {
[_myTest1.layer addAnimation:[self opacityForeverAnimation:1] forKey:@"flash"];
tag++;
}else{
[_myTest1.layer removeAnimationForKey:@"flash"];
tag--;
}
}
-(CABasicAnimation *)opacityForeverAnimation:(float)time
{

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath : @"opacity" ]; // 必须写 opacity 才行。
animation. fromValue = [ NSNumber numberWithFloat : 1.0f ];
animation. toValue = [ NSNumber numberWithFloat : 0.1f ]; // 这是透明度。
animation. autoreverses = YES ;
animation. duration = time;
animation. repeatCount = MAXFLOAT ;
animation. removedOnCompletion = NO ;
animation. fillMode = kCAFillModeForwards ;
animation.timingFunction =[CAMediaTimingFunction functionWithName : kCAMediaTimingFunctionEaseIn]; /// 没有的话是均匀的动画。
return animation;

}

label字体闪烁效果

标签:

原文地址:http://www.cnblogs.com/zhanghuifeng/p/4598412.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!