IOS 作业项目(3) 霓虹灯效果
先上效果图
#import "CHViewController.h"
@interface CHViewController ()
{
int i;
int j;
}
@property NSInteger isStart;
@property (nonatomic,retain) NSMutableArray *viewArray;
@property (nonatomic,retain) UIView *neonView;
@property (nonatomic,retain) NSTimer *timer;
@end
static inline CGRect rectWithScale(CGRect rect,CGFloat scale)
{
rect.size.width+=scale;
rect.size.height+=scale;
return rect;
}
@implementation CHViewController
-(UIColor *)getRandomColor:(NSInteger)max add:(NSInteger)num
{
CGFloat r,g,b;
r=arc4random()%max +num;
g=arc4random()%max +num;
b=arc4random()%max +num;
return [UIColor colorWithRed:r/225.0 green:g/225.0 blue:b/225.0 alpha:1.0f];
}
- (void)viewDidLoad
{
i=0;//视图下标
j=0;
_isStart=0;
///////////背景色
UIView *backGround=[[UIView alloc]initWithFrame:self.view.bounds];
backGround.backgroundColor= [self getRandomColor:31 add:95];
[self.view addSubview:backGround];
//////////标题栏视图设置
UIView *titleView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 20)];
titleView.backgroundColor=[UIColor colorWithRed:33/255.0 green:33/255.0 blue:33/255.0 alpha:0.5];
[backGround addSubview:titleView];
//////////按钮设置
UIButton *button= [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame=CGRectMake(20, backGround.bounds.size.height-130, 280, 40);
[button setTitle:@"Start" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button.backgroundColor=[UIColor whiteColor];
[backGround addSubview:button];
[button addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
///////////////霓虹灯框视图设置
_neonView=[[UIView alloc]initWithFrame:CGRectMake(50, 60, 220, 220)];
_neonView.backgroundColor=[UIColor whiteColor];
[backGround addSubview:_neonView];
//////////////zoom视图入数组
_viewArray=[[NSMutableArray alloc]init];
for (int index=0; index<1000; index++) {
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0,0,5,5)];
CGPoint point=CGPointMake(CGRectGetMidX(_neonView.bounds), CGRectGetMidY(_neonView.bounds));
view.center=point;
view.bounds=rectWithScale(view.bounds, 4.3f);
view.backgroundColor=[self getRandomColor:256 add:0];
[_viewArray addObject:view];
}
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)onClick:(UIButton *)button
{
i=0;
if (_isStart==0) {
_timer=[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(showTime:) userInfo:nil repeats:YES];
_isStart=1;
[button setTitle:@"Stop" forState:UIControlStateNormal];
}
else
{
_isStart=0;
[button setTitle:@"Start" forState:UIControlStateNormal];
[_timer invalidate];
}
}
-(void)showTime:(NSTimer *)timer
{
for (j=0; j<i; j++) {
if (((UIView*)_viewArray[j]).bounds.size.height>=CGRectGetHeight(_neonView.bounds)) {
((UIView*)_viewArray[j]).bounds=CGRectMake(0,0,5,5);
((UIView*)_viewArray[j]).center=CGPointMake(CGRectGetMidX(_neonView.bounds), CGRectGetMidY(_neonView.bounds));
[((UIView*)_viewArray[j]) removeFromSuperview];
//[_neonView addSubview:_viewArray[j]];
}
((UIView*)_viewArray[j]).bounds=rectWithScale(((UIView*)_viewArray[j]).bounds, 5.0f);
// ((UIView*)_viewArray[j]).backgroundColor=[self getRandomColor:256 add:0];
if (i<1000)
[_neonView addSubview:_viewArray[j]];
}
if (i<1000) {
i++;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
/* UIView *view= }*/
}
@end
IOS 作业项目(3) 霓虹灯效果的更多相关文章
- IOS 作业项目(4)步步完成 画图 程序(中)
一,承接上文,继续本文 [UIButton buttonWithType:UIButtonTypeRoundedRect]; 如此声明的按钮才会有点击闪动的效果!如果直接frame方式声明就不会有. ...
- IOS 作业项目(2) 画图(保存,撤销,笔粗细设定功能)
先上效果图
- IOS 作业项目(1) 关灯游戏 (百行代码搞定)
1,准备工作,既然要开关灯,就需要确定灯的灯的颜色状态 首先想到的是扩展UIColor
- IOS 作业项目 TableView两个section中cell置顶功能实现
点击cell会置顶,其他的下移
- IOS 作业项目(4)步步完成 画图 程序(问题处理)终结
一,解决换色程序崩溃问题 程序崩溃是因为颜色的内存被释放,添加如下类的内容即可 @implementation TuyaPath - (id)init { self = [super init]; i ...
- IOS 作业项目(4)步步完成 画图 程序(剧终)
// // CHViewController.m // SuperDrawingSample // // Created by JaikenLI on 13-11-21. // Copyrig ...
- IOS 作业项目(4)步步完成 画图 程序(中续)
一,程序布局整理 前言://1,程序启动//2,程序流程框架//3,程序界面一致//4,程序界面功能, //这里只做页面的固定功能, //在首次创建界面时,我们会指定好固定事件触发前的固定方法 //至 ...
- IOS 作业项目(4)步步完成 画图 程序(上)
先上流程图
- GitHub Android 最火开源项目Top20 GitHub 上的开源项目不胜枚举,越来越多的开源项目正在迁移到GitHub平台上。基于不要重复造轮子的原则,了解当下比较流行的Android与iOS开源项目很是必要。利用这些项目,有时能够让你达到事半功倍的效果。
1. ActionBarSherlock(推荐) ActionBarSherlock应该算得上是GitHub上最火的Android开源项目了,它是一个独立的库,通过一个API和主题,开发者就可以很方便 ...
随机推荐
- ARM堆栈及特殊指令
ARM7支持四种堆栈模式:满递减(FD).满递增(FA).空递减(ED).空递增(EA) FD:堆栈地址从上往下递减,且指针指向最后一个入栈元素.FA:堆栈地址从下往上递增,且指针指向最后一个入栈元素 ...
- Visual Studio 2012出现“无法访问T-SQL组件和安装了不兼容伯 DacFx版本”的解决办法
参考:Visual Studio 2012出现“无法访问T-SQL组件和安装了不兼容伯 DacFx版本”的解决办法 Vs2012的下载地址: https://msdn.microsoft.com/en ...
- 利用sklearn计算文本相似性
利用sklearn计算文本相似性,并将文本之间的相似度矩阵保存到文件当中.这里提取文本TF-IDF特征值进行文本的相似性计算. #!/usr/bin/python # -*- coding: utf- ...
- Objective-C:Category
Category可以在不需要创建子类或是修改原始类的基础上,动态为已经存在的类添加新的行为(方法),,这样可以保证类的原始设计规模较小,功能增加时再逐步扩展:实现了类的相关方法的模块化,把不同的类方法 ...
- BZOJ1737 [Usaco2005 jan]Naptime 午睡时间
断环然后裸DP就好了... $f[i][j][k]$表示1号时间段没有被算入答案,到了第$i$个时间段,一共选了$j$个时间段,$k = 0 /1$表示第i个时间段有没有被算进答案的最优值 $g[i] ...
- linux 设置windows共享
在linux下需要设置windows共享. 我们使用SMBA来实现. 1.查看是否安装smba. rpm -qa | grep samba 如果没有安装,则去 www.rpmfind.net 下载sm ...
- C#入门篇6-5:字符串操作 测试StringBuilder的运行效率
//测试StringBuilder的运行效率 public static void Fun2() { #region string string str = "我喜欢编程!"; / ...
- 目前几款基于html5的前端框架:如Bootstrap、Foundation、Semantic UI 、Amaze UI
Bootstrap是由Twitter在2011年8月推出的开源WEB前端框架,集合CSS 和HTML,使用了最新的浏览器技术,为快速WEB开发提供了一套前端工具包,包括布局.网格.表格.按钮.表单.导 ...
- [Jquery]网页定位导航特效
描述:左右联动的导航,非常适合展示页面内容多,区块划分又很明显的,点击右边固定导航项时,左边的内容跟着切换.滑动滚动条的时候,右边的导航也随着左边的展示而进行高亮切换. 思路:比较滚动距离和楼层距离( ...
- 编码为multipart/form-data自定义类型(包括文件)如何自动绑定到webapi的action的参数里
application/x-www-form-urlencoded与 multipart/form-data: Fom表单中如果没有type=file的控件,用默认的application/x-www ...