//创建万花筒视图

for (NSInteger i = 0; i < 16; i++) {
        centerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300 - 20 * i, 300 - 20 * i)];
        centerView.center = self.window.center;
        centerView.layer.borderColor = [UIColor grayColor].CGColor;
        centerView.layer.borderWidth = 1;
        centerView.tag = 200 + i;
        centerView.layer.cornerRadius = 150 - i * 10;
        [self.window addSubview:centerView];
        [centerView release];
    }
   
    //创建控制按钮
    //启动按钮
    UIButton *startButton = [UIButton buttonWithType:UIButtonTypeSystem];
    startButton.frame = CGRectMake(150, 90, 75, 30);
    startButton.backgroundColor = [UIColor grayColor];
    [startButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [startButton setTitle:@"启动" forState:UIControlStateNormal];
    startButton.titleLabel.font = [UIFont systemFontOfSize:25];
    [startButton addTarget:self action:@selector(pressStartButton) forControlEvents:UIControlEventTouchUpInside];
    [self.window addSubview:startButton];
    //停止按钮
    UIButton *stopButton = [UIButton buttonWithType:UIButtonTypeSystem];
    stopButton.frame = CGRectMake(150, 597, 75, 30);
    stopButton.backgroundColor = [UIColor grayColor];
    [stopButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    stopButton.titleLabel.font = [UIFont systemFontOfSize:25];
    [stopButton setTitle:@"停止" forState:UIControlStateNormal];
    [stopButton addTarget:self action:@selector(pressStopButton) forControlEvents:UIControlEventTouchUpInside];
    [self.window addSubview:stopButton];

//需要用到的方法
//点击button启动万花筒
- (void) pressStartButton {
    //使用了定时器, 使视图达到转动的效果
    myTimer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(colorChange) userInfo:nil repeats:YES];
}

//点击button停止万花筒
- (void) pressStopButton {
    //当定时器停止运转的时候, 万花筒的效果也就自然结束
    [myTimer invalidate];
}

//为视图随机添加颜色, 并使靠内视图的颜色赋给靠外视图
- (void)colorChange {
    for (NSInteger i = 15; i >= 0; i--) {
       
        //使用tag值寻找到相应的视图
        [self.window viewWithTag:214 - i].backgroundColor = [self.window viewWithTag:215 - i].backgroundColor;
        [self.window viewWithTag:215 - i].backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255. green:arc4random() % 256 / 255. blue:arc4random() % 256 / 255. alpha:arc4random() * 11 / 10.];
    }
}

转载于:https://www.cnblogs.com/zhangwu/p/4565630.html

KaleidoscopeGame相关推荐

最新文章

  1. VTK:隐式函数之BooleanOperationImplicitFunctions
  2. 题目:JavaWeb乐购资源管理系统(附源码链接免费下载)
  3. 合肥南站,你怎么这么棒?人民日报都夸你了!
  4. 使用FormData进行Ajax请求上传文件
  5. css3点击会移动到点,CSS3过渡点击事件
  6. sql server 高可用故障转移(6)
  7. 不要打我,不要打我,不要打我啊啊
  8. 用Python实现一个动物识别专家系统--人工智能
  9. 计算机五大类型,操作系统目前有五大类型
  10. php匹配ubb,UBB类 php UBB 解析实现代码
  11. C++实现高质量游戏游戏!!!不点开你会后悔的!!!包括 买彩票游戏 勇者游戏 等 5个游戏
  12. 数商云B2B跨境电子商务平台综合服务解决方案
  13. 你不可不知的Java引用类型之——SoftReference源码详解
  14. Android 动画解析(一) 逐帧动画(Frame Animation)
  15. 【Spring Boot实战】源码解析Spring Boot自动配置原理
  16. Docker Volume原理及使用
  17. 以太坊V神大著:去中心化社会:寻找Web3的灵魂
  18. 【通知】关于SRRC认证无线电发射设备型号核准的通知
  19. 计算机stem案例,【stem教育项目教学案例】_STEM教育理念下的“三维创意设计”课程教学案例...
  20. 100天精通Python(数据分析篇)——第66天:Pandas透视表基础+实战案例(pivot_table函数)

热门文章

  1. 新一代垃圾回收器ZGC的探索与实践
  2. 分布式锁原理——redis分布式锁,zookeeper分布式锁
  3. 如何设计一个良好的接口?
  4. 也许,这样理解 HTTPS 更容易
  5. 学习编程的25个“坑”,你踩到了吗?
  6. Fabio技术手册(1):概述和快速上手
  7. 关于feign调用时,session丢失的解决方案
  8. Consul入门02 - 运行Consul代理
  9. Andriod --- JetPack (七):Room + ViewModel + LiveData 增删改查实例
  10. Android --- 订单编号怎样不重复?一秒钟如果有n个人同时下单怎么解决?凌晨12点限量抢购1000件商品,直到抢完为止订单编号怎么处理?