animation跑马灯动画实现两种方法
来源:互联网 发布:现代单片机的发展趋势 编辑:程序博客网 时间:2024/03/29 06:45
//方法一@interface ViewController ()@end@implementation ViewController{ UILabel * _label ;}- (void)viewDidLoad { [super viewDidLoad]; _label = [[UILabel alloc]initWithFrame:CGRectMake(0, 30, 100, 40)]; _label.text = @"游来游去"; _label.textAlignment= NSTextAlignmentCenter; _label.backgroundColor = [UIColor orangeColor]; [self.view addSubview:_label]; //实现从左到右 [self leftToRight];}-(void)rightToLeft{ //从右到左 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:4]; _label.frame = CGRectMake(0, 30, 100, 40); [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(leftToRight)]; [UIView commitAnimations]; }-(void)leftToRight{ //实现从左到右 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:4]; _label.frame = CGRectMake(320, 30, 100, 40); //设置谁去调用动画的结束方法(设置代理) [UIView setAnimationDelegate:self]; //设置动画将要开始的方法 [UIView setAnimationWillStartSelector:@selector(animationStart)]; //设置动画的结束方法 谁什么情况下做什么事情 [UIView setAnimationDidStopSelector:@selector(rightToLeft)]; [UIView commitAnimations]; NSLog(@"动画块的代码执行完了,但是动画还没有结束 ;代码的执行 和 动画的执行 是 并列 的");}-(void)animationStart{ NSLog(@"动画要开始了");}@end
//方法二UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, 100, 40)]; label.backgroundColor = [UIColor purpleColor] ; label.text = @"跑马灯"; [self.view addSubview:label]; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:2]; //设置动画的重复次数 注意顺序;写在结束坐标点的上方; //LONG_MAX:无穷大 [UIView setAnimationRepeatCount:LONG_MAX]; //设置是否执行反向动画 ; [UIView setAnimationRepeatAutoreverses:YES]; label.frame = CGRectMake(320, 20, 100, 40); [UIView commitAnimations];
8 0
- animation跑马灯动画实现两种方法
- Android TestView实现跑马灯效果的两种方法
- TextView跑马灯效果的两种实现方法
- 文字跑马灯的两种方法
- 跑马灯效果的两种实现
- TextView跑马灯的两种实现
- Android Animation 两种动画实现 Tween Animation和Frame Animation
- android animation动画效果的两种实现方式
- 动画Animation两种实现方式的不同效果
- Android 文字自动滚动(跑马灯)效果的两种实现方法
- Android 文字自动滚动(跑马灯)效果的两种实现方法
- Android 文字自动滚动(跑马灯)效果的两种实现方法
- android TextView不用获得焦点实现跑马灯效果 两种方法
- Android 文字自动滚动(跑马灯)效果的两种实现方法
- Android 文字自动滚动(跑马灯)效果的两种实现方法
- Android 文字自动滚动(跑马灯)效果的两种实现方法[特别好使]
- Android 文字自动滚动(跑马灯)效果的两种实现方法
- Android 文字自动滚动(跑马灯)效果的两种实现方法
- struts2-拦截器(一)
- Android视图SurfaceView的实现原理分析
- PageRank算法
- Linux大小端判断
- jquery判断checkbox是否选中及改变checkbox状态
- animation跑马灯动画实现两种方法
- java JNDI路劲配置
- jsp
- Session二
- 第16周项目——阅读程序4
- 练习5-2 模仿函数getint的实现方法,编写一个读取浮点数的函数getfloat。getfloat函数的返回值应该是什么类型
- QT自定义窗口(无边框,自由拖动)
- Android SQLite数据库储存数据
- 程序员,如何写好文档?