#import "ViewController.h"
#import "PicFlowArray.h"
#define PICFLOW_PAGE_GAP 5
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIImageView * iv1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 130, arc4random()%100)];
iv1.backgroundColor = [UIColor redColor];
UIImageView * iv2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 130, arc4random()%100)];
iv2.backgroundColor = [UIColor blackColor];
UIImageView * iv3 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 130, arc4random()%100)];
iv3.backgroundColor = [UIColor yellowColor];
UIImageView * iv4 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 130, arc4random()%100)];
iv4.backgroundColor = [UIColor orangeColor];
UIImageView * iv5 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 130, arc4random()%100 + 50)];
iv5.backgroundColor = [UIColor blackColor];
UIImageView * iv6 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 130, arc4random()%100 + 50)];
iv6.backgroundColor = [UIColor whiteColor];
UIImageView * iv7 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 130, arc4random()%100 + 50)];
iv7.backgroundColor = [UIColor purpleColor];
UIImageView * iv8 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 130, arc4random()%100 + 50)];
iv8.backgroundColor = [UIColor blueColor];
UIImageView * iv9 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 130, arc4random()%100 + 50)];
iv9.backgroundColor = [UIColor greenColor];
NSArray * array = [NSArray arrayWithObjects:iv1,iv2,iv3,iv4,iv5,iv6,iv7,iv8,iv9, nil];
[self sortPicArray:array];
}
- (void)sortPicArray:(NSArray *)tmpArray
{
//NSMutableArray * ASF = [[NSMutableArray alloc] initWithCapacity:0];
PicFlowArray * firstColArray = [[PicFlowArray alloc] init];
PicFlowArray * secondColArray = [[PicFlowArray alloc] init];
firstColArray.originX = 20;
firstColArray.originY = 20;
secondColArray.originX = 20 + 130 + 20;
secondColArray.originY = 20;
for(int i = 0; i < [tmpArray count]; i++)
{
if(i == 0)
{
UIImageView * tmpImageView = [tmpArray objectAtIndex:i];
CGSize size = tmpImageView.frame.size;
tmpImageView.frame = CGRectMake(firstColArray.originX, firstColArray.originY, size.width, size.height);
[self.view addSubview:tmpImageView];
[firstColArray.array addObject:tmpImageView];
firstColArray.originY = size.height + firstColArray.originY + PICFLOW_PAGE_GAP;
}
else
{
if(firstColArray.originY > secondColArray.originY)
{
UIImageView * tmpImageView = [tmpArray objectAtIndex:i];
CGSize size = tmpImageView.frame.size;
tmpImageView.frame = CGRectMake(secondColArray.originX, secondColArray.originY, size.width, size.height);
[self.view addSubview:tmpImageView];
[secondColArray.array addObject:tmpImageView];
secondColArray.originY = secondColArray.originY + size.height + PICFLOW_PAGE_GAP;
}
else
{
UIImageView * tmpImageView = [tmpArray objectAtIndex:i];
CGSize size = tmpImageView.frame.size;
tmpImageView.frame = CGRectMake(firstColArray.originX, firstColArray.originY, size.width, size.height);
[self.view addSubview:tmpImageView];
[firstColArray.array addObject:tmpImageView];
firstColArray.originY = firstColArray.originY + size.height + PICFLOW_PAGE_GAP;
}
}
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end