IOS 霓虹灯效果
2012-08-23 16:37
393 查看
//初始化视图
- (void) initViews{
//红色视图
UIView *redView=[[UIView alloc] initWithFrame:CGRectMake(20, 20, 280, 280)];
redView.backgroundColor=[UIColor redColor];
//视图的标签,标示一个视图对象
redView.tag=1;
[self.view addSubview:redView];
[redView release];
//橙色视图
UIView *oriangeView=[[UIView alloc] initWithFrame:CGRectMake(20, 20, 240, 240)];
oriangeView.backgroundColor=[UIColor orangeColor];
oriangeView.tag=2;
[redView addSubview:oriangeView];
[oriangeView release];
//黄色视图
UIView *yellowView=[[UIView alloc] initWithFrame:CGRectMake(20, 20, 200, 200)];
yellowView.backgroundColor=[UIColor yellowColor];
yellowView.tag=3;
[oriangeView addSubview:yellowView];
[yellowView release];
//绿色视图
UIView *greenView=[[UIView alloc] initWithFrame:CGRectMake(20,20, 160, 160)];
greenView.backgroundColor=[UIColor greenColor];
greenView.tag=4;
[yellowView addSubview:greenView];
[greenView release];
//青色视图
UIView *cyanView=[[UIView alloc] initWithFrame:CGRectMake(20, 20, 120, 120)];
cyanView.backgroundColor=[UIColor cyanColor];
cyanView.tag=5;
[greenView addSubview:cyanView];
[cyanView release];
//蓝色视图
UIView *blueView=[[UIView alloc] initWithFrame:CGRectMake(20, 20, 80, 80)];
blueView.backgroundColor=[UIColor blueColor];
blueView.tag=6;
[cyanView addSubview:blueView];
[blueView release];
//紫色视图
UIView *purpleView=[[UIView alloc] initWithFrame:CGRectMake(20, 20, 40, 40)];
purpleView.backgroundColor=[UIColor purpleColor];
purpleView.tag=7;
[blueView addSubview:purpleView];
[purpleView release];
}
//实现翻页效果
- (void)xuanzhuang:(id) sender{
//获取当前画图的设备上下文
CGContextRef context=UIGraphicsGetCurrentContext();
//开始准备动画
[UIView beginAnimations:@"*******" context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//设置动画持续时间
[UIView setAnimationDuration:0.5];
//因为没有给该Controller添加实例变量,所以用以下方法获得View
UIView *parentView=[self.view viewWithTag:1];
//设置动画效果
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:parentView cache:YES]; //从上到下
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:parentView cache:YES]; //从下往上
// [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:parentView cache:YES]; //从左到右
// [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:parentView cache:YES]; //从右到左
//设置动画委托
[UIView setAnimationDelegate:self];
//当动画啊结束时 调用animationFinished方法
[UIView setAnimationDidStopSelector:@selector(animationFinished:)];
//提交动画
[ UIView commitAnimations];
}
//处理颜色的改变
- (void) showChangeView:(id) sender{
[self xuanzhuang:nil];
NSLog(@"调用showChange函数!!");
//每次调用,当前颜色加1
currentColor++;
if (currentColor>6) {
currentColor=0;
}
colorArray=[NSArray arrayWithObjects:[UIColor redColor],[UIColor orangeColor],[UIColor yellowColor],[UIColor greenColor],[UIColor cyanColor],[UIColor blueColor],[UIColor purpleColor], nil];
//初始化视图数组
for (int i=1; i<=7; i++) {
//存的是7个视图的对象
[viewArray addObject:[self.view viewWithTag:i]];
}
// NSLog(@"颜色数组大小为:%d",[ colorArray count]);
// NSLog(@"视图大小为:%d",[viewArray count]);
//关键代码,循环设置背景色
for (int i=0; i<7-currentColor; i++) {
[[viewArray objectAtIndex:i] setBackgroundColor:[colorArray objectAtIndex:i+currentColor]];
}
for (int i=6-currentColor,j=0; i<7;j++,i++) {
[[viewArray objectAtIndex:i] setBackgroundColor:[colorArray objectAtIndex:j]];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"调用viewDidLoad方法!!!");
self.view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460 )];
self.view.backgroundColor=[UIColor clearColor];
//初始化视图
[self initViews];
//定义一个定时器每隔0.5秒循环调用showChangeView:方法,这个定时器的用法如果还不是很熟悉的话,可以看我的 其他文章,有对他的详细讲解
NSTimer *timer=[NSTimer timerWithTimeInterval:0.5 target:self selector:@selector(showChangeView:) userInfo:nil repeats:YES];
NSRunLoop *runloop=[NSRunLoop currentRunLoop];
[runloop addTimer:timer forMode:NSDefaultRunLoopMode];
}
相关文章推荐
- IOS开发入门基本知识——UIView和NSTimer形成的霓虹灯效果
- iOS 霓虹灯效果
- ios霓虹灯效果(没基础也可以做出好看的霓虹灯)
- 用iOS的UI知识编出霓虹灯效果(经典小题)
- iOS 霓虹灯效果(同种颜色依次向外扩展)
- IOS 霓虹灯效果(oc)
- IOS 霓虹灯效果
- IOS 作业项目(3) 霓虹灯效果
- OCiOS开发:表格视图实现腾讯好友列表展开收缩效果
- ios view与view间切换的动画效果
- iOS tabbarItem的颜色都是白色,点击其中一个,其他的不变,没有点中的效果
- iOS 贝塞尔曲线实现圆角效果
- iOS之iPhone解锁界面的"滑动来解锁"闪烁动画效果,好奇的赶紧进来取走,别看了,说的就是你0.0
- android布局之帧布局-----霓虹灯效果实现
- iOS开发之剖析"秘密"App内容页面效果(一)
- iOS开发中点击UITabBarItem弹出一个控制器(如常见未登录用户点击购物车弹出登录页面的效果)
- IOS-ScrollView创造Android-ViewPager效果
- iOS放大镜、调试工具、图片滤镜、导航渐变、动画效果等源码
- ios动画中抖动动画效果的实现与CALayer动画的基本理解
- iOS 8 Spring Animation[IOS 7.0以后动画效果超赞]---弹簧震动效果