KaleidoscopeGame
生活随笔
收集整理的這篇文章主要介紹了
KaleidoscopeGame
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?
//創(chuàng)建萬花筒視圖
?
??????? 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];
??? }
???
??? //創(chuàng)建控制按鈕
??? //啟動按鈕
??? 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];
//需要用到的方法
//點(diǎn)擊button啟動萬花筒
- (void) pressStartButton {
??? //使用了定時器, 使視圖達(dá)到轉(zhuǎn)動的效果
??? myTimer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(colorChange) userInfo:nil repeats:YES];
}
//點(diǎn)擊button停止萬花筒
- (void) pressStopButton {
??? //當(dāng)定時器停止運(yùn)轉(zhuǎn)的時候, 萬花筒的效果也就自然結(jié)束
??? [myTimer invalidate];
}
//為視圖隨機(jī)添加顏色, 并使靠內(nèi)視圖的顏色賦給靠外視圖
- (void)colorChange {
??? for (NSInteger i = 15; i >= 0; i--) {
???????
??????? //使用tag值尋找到相應(yīng)的視圖
??????? [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.];
??? }
}
轉(zhuǎn)載于:https://www.cnblogs.com/zhangwu/p/4565630.html
總結(jié)
以上是生活随笔為你收集整理的KaleidoscopeGame的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 常用代码整理(重要)
- 下一篇: UI控件问题和XCode编译警告和错误解