//
// 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