label字体闪烁效果
2015-06-24 18:46
393 查看
- (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;
}
[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;
}
相关文章推荐
- 极客学院视频下载
- js--小结⑦---格式转换
- 如何开始创业
- android5.0 imx6 some TF car(micro sd card) boot failed
- 什么是Hessian协议呢?
- 在使用storyboard的时候,适配6plus的时候,模拟器的两边会出现很细的白边
- 学习笔记-基础知识9-集合框架(2)
- 为iOS(iPhone)开发环境编译OpenSSL库
- 在intellij idea 中进行android 单元测试
- 最长上升子序列nlogn算法
- 59.删除字符串中的小写字母c
- 如何迅速学习一种新知识?
- REST架构风格
- OC1_协议语句
- zookeeper之实践一
- R语言笔记
- 黑马程序员---集合类
- iptables详解 ——linux端口映射学习
- git基本用法
- Cocos2d-Lua(Quick-Cocos2d-x)内存释放