颜色块由外到内的闪动NSTimer ...
2016-01-07 13:31
260 查看
#import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //生成几个视图并为几个视图添加颜色(从大到小) for (NSInteger i = 7; i >= 1; i--) { //只要不出界就行 UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50 * i, 50 * i)]; //视图颜色随机 view.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255. green:arc4random() % 256 / 255. blue:arc4random() % 256 / 255. alpha:1.0]; //视图中心点是屏幕的中心点 view.center = self.view.center; //视图tag值 view.tag = 100 + i; [self.view addSubview:view]; [view release]; } //计时器, 调用改变颜色的函数 [NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(changeColor) userInfo:nil repeats:YES]; } - (void)changeColor { //交换视图6次 for (NSInteger i = 1; i <= 6; i++) { UIView *view1 = (UIView *)[self.view viewWithTag:100 + i]; UIView *view2 = (UIView *)[self.view viewWithTag:100 + i + 1]; //大的赋给小的 view1.backgroundColor = view2.backgroundColor; } //大的再随机产生颜色view UIColor *color = [UIColor colorWithRed:arc4random() % 256 / 255. green:arc4random() % 256 / 255. blue:arc4random() % 256 / 255. alpha:1.0]; UIView *view = (UIView *)[self.view viewWithTag:107]; view.backgroundColor = color; }
相关文章推荐
- android中的tween动画(也叫view动画)原理以及使用详解
- eclipse 提高开发效率方法
- Unity3D Editor 扩展
- 职场邮件忌讳
- LFS 中文版手册发布:如何打造自己的 Linux 发行版
- 平时用的sublime插件
- UITableView 属性集合
- XHProf的安装和使用(PHP性能测试神器)
- 在SharePoint 上配置 Project 2013
- C#正则表达式开源工具
- Struts2动态方法调用(DMI)小问题
- 我的家庭保险方案推荐
- 几种更新(Update语句)查询的方法【转】
- linux上传下载文件
- mysql having
- AVCaptureDevice iOS摄像头属性
- 切记初始化
- 图片大小设置
- 在使用eclipse 运行 maven install的时候,出现这个错误:Unable to locate the Javac Compiler in:…
- 使用ssh公钥实现免密码登录其他主机