iOS动态彩条

//
//  YViewController.m
//  Day3HW
//
//  Created by roblonely on 15-7-22.
//  Copyright (c) 2015年 Yangjiyao. All rights reserved.
//

#import "YViewController.h"
#define COUNT 77
@interface YViewController ()

@end

@implementation YViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

CGFloat width,height;

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    width = self.view.frame.size.width;
    height = self.view.frame.size.height;
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self startChangeColor:self.view];
    
    for (int i = 0; i<COUNT; i++) {
        CGFloat tWidth = width/COUNT;
        CGFloat x = tWidth*i;
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(x, height, tWidth, 0)];
        [self start:view];
        [self.view addSubview:view];
    }
}


-(void) start:(UIView *)view{
    
    CGFloat dur = arc4random()%101 *0.015+0.8;
    [UIView animateWithDuration:dur animations:^{
        CGFloat tHeight = height * (arc4random()%101)/100;
        view.frame = CGRectMake(view.frame.origin.x, height-tHeight,  view.frame.size.width,tHeight);
        CGFloat red = arc4random()%101 *0.01;
        CGFloat green = arc4random()%101 *0.01;
        CGFloat blue = arc4random()%101 *0.02;
        view.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:1];
    } completion:^(BOOL finished){
        [self start:view];
    }];

}

-(void)didReceiveMemoryWarning{
    [super didReceiveMemoryWarning];
    NSLog(@"警告:内存占用过大!");

}

-(void) startChangeColor:(UIView *)view{
    
    CGFloat dur = arc4random()%101 *0.015+0.8;
    [UIView animateWithDuration:dur animations:^{
        CGFloat red = arc4random()%101 *0.01;
        CGFloat green = arc4random()%101 *0.01;
        CGFloat blue = arc4random()%101 *0.01;
        view.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:0.4];
    } completion:^(BOOL finished){
        [self startChangeColor:view];
    }];
    
}

-(BOOL)shouldAutorotate{
    //不仅要在Devoice中设置可旋转的方向,还要在这里返回YES才能在这个ViewController中旋转
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations{
    //这里返回这个枚举类型可以支持所有方向的转换
    return UIInterfaceOrientationMaskAll;
}



@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值