您的位置:首页 > 产品设计 > UI/UE

IOS开发入门基本知识——UIView和NSTimer形成的霓虹灯效果

2013-06-28 20:19 621 查看
通过UIview多视图的叠加,灵活利用UIView的属性值,NStimer的控制,输出多彩的霓虹灯效果



前半部分,UIView的实现并不难,代码也很好理解

@interface RootViewController ()

{

UIView *aView;

UIView *bView;

UIView *cView;

UIView *dView;

UIView *eView;

UIView *fView;

UIView *gView;

}

@end

- (void)viewDidLoad

{

[super viewDidLoad];

aView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)];

[aView setBackgroundColor:[UIColor redColor]];

[self.view addSubview:aView];

[aView release];

bView=[[UIView alloc]initWithFrame:CGRectMake(20, 20, 280, 420)];

[bView setBackgroundColor:[UIColor blueColor]];

[aView addSubview:bView];

[bView release];

cView=[[UIView alloc]initWithFrame:CGRectMake(20, 20, 240, 380)];

[cView setBackgroundColor:[UIColor greenColor]];

[bView addSubview:cView];

[cView release];

dView=[[UIView alloc]initWithFrame:CGRectMake(20, 20, 200, 340)];

[dView setBackgroundColor:[UIColor orangeColor]];

[cView addSubview:dView];

[dView release];

eView=[[UIView alloc]initWithFrame:CGRectMake(20, 20, 160, 300)];

[eView setBackgroundColor:[UIColor purpleColor]];

[dView addSubview:eView];

[eView release];

UIView一旦固定好,就view之间的交互,不断向外扩展

先设定一个nstimer 时间控制器都写在viewdidload里面

NSTimer *t=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(Go:) userInfo:nil repeats:YES];

然后是Go:的方法实现

-(void)Go:(id)sender

{

UIView *changeView=[[UIView alloc]init];

changeView.backgroundColor=aView.backgroundColor;

aView.backgroundColor=bView.backgroundColor;

bView.backgroundColor=cView.backgroundColor;

cView.backgroundColor=dView.backgroundColor;

dView.backgroundColor=eView.backgroundColor;

eView.backgroundColor=changeView.backgroundColor;

}

随着时间的移动,通过一个中间变量,实现每个视图之间的交换。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: