霓虹灯的制作(正向,反向,以及停止)
来源:互联网 发布:图形界面c语言 知乎 编辑:程序博客网 时间:2024/06/05 19:24
//先创建一个霓虹灯视图 NSArray *arr = [NSArray arrayWithObjects:[UIColor purpleColor],[UIColor cyanColor],[UIColor blueColor],[UIColor greenColor],[UIColor yellowColor],[UIColor orangeColor],[UIColor redColor], nil]; for (int i = 0; i < 7; i++) { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(20 + i * 20 , 120 + i * 20, 280 - i * 20 * 2, 280 - i * 20 * 2)]; view.backgroundColor = arr[i]; view.tag = 100 + i; [_containerView addSubview:view]; [view release]; }
//创建按钮控制霓虹灯停止 UIButton *bun = [UIButton buttonWithType:UIButtonTypeSystem]; bun.frame = CGRectMake(50, 420, 220, 40); bun.layer.cornerRadius = 5; [bun setTitle:@"停止" forState:UIControlStateNormal]; [bun addTarget:self action:@selector(bun:) forControlEvents:UIControlEventTouchUpInside]; [_containerView addSubview:bun];
//创建让霓虹灯反向运行的按钮 UIButton *stop = [UIButton buttonWithType:UIButtonTypeSystem]; stop.frame = CGRectMake(50, 480, 220, 40); stop.layer.cornerRadius = 5; [stop setTitle:@"反向" forState:UIControlStateNormal]; [stop addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside]; [_containerView addSubview:stop];
//设置时间间隔 _time = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(test) userInfo:nil repeats:YES];
//停止事件- (void)bun:(UIButton *)btn{ [_time invalidate];}
//正向运行点击事件- (void)test{ UIView *view = [[UIView alloc] init]; view.backgroundColor = [_containerView viewWithTag:100].backgroundColor; for (int i = 100; i < 107; i++) { [_containerView viewWithTag:i].backgroundColor = [_containerView viewWithTag:i + 1].backgroundColor; } [_containerView viewWithTag:106].backgroundColor = view.backgroundColor; [view release];}
//反向运行点击事件- (void)click{ _time = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(clicks) userInfo:nil repeats:YES];}- (void)clicks{ UIView *view = [[UIView alloc] init]; view.backgroundColor = [_containerView viewWithTag:106].backgroundColor; for (int i = 106; i > 99; i--) { [_containerView viewWithTag:i].backgroundColor = [_containerView viewWithTag:i - 1].backgroundColor; } [_containerView viewWithTag:100].backgroundColor = view.backgroundColor; [view release];}
通过以上步骤,就基本完成了一个可以正向,反向,以及停止的霓虹灯制作.
file:///Users/lanouhn/Desktop/1.gif
0 0
- 霓虹灯的制作(正向,反向,以及停止)
- 如何实现反向代理?与正向代理的区别以及Nginx 反向代理优势
- 正向反向代理的理解
- 关于正向代理以及反向代理
- 采用PWM的电压反相器以及推广的正向2、3倍压 反向倍压
- 正向代理与反向代理的区别
- 支持正向反向Geocoder的源码
- 正向代理与反向代理的区别
- 正向代理与反向代理的区别
- 正向代理与反向代理的区别
- 正向代理与反向代理的区别
- 正向代理与反向代理的区别
- 正向代理与反向代理的区别
- string类的正向和反向查找
- 正向代理与反向代理的区别
- 正向代理和反向代理的区别
- 正向代理与反向代理的区别
- 正向代理与反向代理的区别
- 【并查集】Cube Stacking(关系并查集)
- HDU 1073 Online Judge(字符串输入方面的经验)
- hdu 1573 中国剩余定理
- NSArray的用法
- java swing开发的图像生成器demo实例源代码下载,实现绘制图像,截屏功能。
- 霓虹灯的制作(正向,反向,以及停止)
- 深入理解与优化Adapter
- 矩形嵌套问题-ACM集训
- 【互联网】重温经典面试题---二进制编号
- 一道曾经微软的面试题
- Mysql中通过processlist方式查询Mysql数据库当前连接的用户及会话信息
- UVA 10160 - Servicing Stations
- C# 访问Domino对象,拆离富文本域中的附件
- 表达式求值