Skip to content

Commit

Permalink
修改数据结构
Browse files Browse the repository at this point in the history
  • Loading branch information
董知樾 authored and 董知樾 committed Mar 10, 2017
1 parent 73e93ae commit df19f13
Show file tree
Hide file tree
Showing 6 changed files with 300 additions and 245 deletions.
66 changes: 41 additions & 25 deletions VILLOID/Layout/YYLayoutDefine.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,47 @@
@implementation YYLayoutDefine
NSArray * getLayoutDafines() {

NSArray *array = @[@[@{@"x":@(0),@"y":@(0),@"w":@(1),@"h":@(1)},
@{@"x":@(0),@"y":@(1),@"w":@(1),@"h":@(1)},
@{@"x":@(0),@"y":@(2),@"w":@(1),@"h":@(1)},
@{@"x":@(1),@"y":@(0),@"w":@(1),@"h":@(1)},
@{@"x":@(1),@"y":@(1),@"w":@(1),@"h":@(1)},
@{@"x":@(1),@"y":@(2),@"w":@(1),@"h":@(1)},
@{@"x":@(2),@"y":@(0),@"w":@(1),@"h":@(1)},
@{@"x":@(2),@"y":@(1),@"w":@(1),@"h":@(1)},
@{@"x":@(2),@"y":@(2),@"w":@(1),@"h":@(1)},
],
@[@{@"x":@(0),@"y":@(0),@"w":@(2),@"h":@(1)},
@{@"x":@(2),@"y":@(0),@"w":@(1),@"h":@(1)},
@{@"x":@(0),@"y":@(1),@"w":@(2),@"h":@(1)},
@{@"x":@(2),@"y":@(1),@"w":@(1),@"h":@(2)},
@{@"x":@(0),@"y":@(2),@"w":@(2),@"h":@(1)},
],
@[@{@"x":@(0),@"y":@(0),@"w":@(1),@"h":@(3)},
@{@"x":@(1),@"y":@(0),@"w":@(2),@"h":@(2)},
@{@"x":@(1),@"y":@(2),@"w":@(2),@"h":@(1)},
],
@[@{@"x":@(0),@"y":@(0),@"w":@(1),@"h":@(2)},
@{@"x":@(1),@"y":@(0),@"w":@(2),@"h":@(2)},
@{@"x":@(0),@"y":@(2),@"w":@(1),@"h":@(1)},
@{@"x":@(1),@"y":@(2),@"w":@(2),@"h":@(1)},
]];
NSArray *array = @[@{
@"rowNumber":@(3),
@"arrangeNumber":@(3),
@"itemCoordinaties":@[@{@"x":@(0),@"y":@(0),@"w":@(1),@"h":@(1)},
@{@"x":@(0),@"y":@(1),@"w":@(1),@"h":@(1)},
@{@"x":@(0),@"y":@(2),@"w":@(1),@"h":@(1)},
@{@"x":@(1),@"y":@(0),@"w":@(1),@"h":@(1)},
@{@"x":@(1),@"y":@(1),@"w":@(1),@"h":@(1)},
@{@"x":@(1),@"y":@(2),@"w":@(1),@"h":@(1)},
@{@"x":@(2),@"y":@(0),@"w":@(1),@"h":@(1)},
@{@"x":@(2),@"y":@(1),@"w":@(1),@"h":@(1)},
@{@"x":@(2),@"y":@(2),@"w":@(1),@"h":@(1)},
]
},
@{
@"rowNumber":@(3),
@"arrangeNumber":@(3),
@"itemCoordinaties":@[@{@"x":@(0),@"y":@(0),@"w":@(2),@"h":@(1)},
@{@"x":@(2),@"y":@(0),@"w":@(1),@"h":@(1)},
@{@"x":@(0),@"y":@(1),@"w":@(2),@"h":@(1)},
@{@"x":@(2),@"y":@(1),@"w":@(1),@"h":@(2)},
@{@"x":@(0),@"y":@(2),@"w":@(2),@"h":@(1)},
],
},
@{
@"rowNumber":@(3),
@"arrangeNumber":@(3),
@"itemCoordinaties":@[@{@"x":@(0),@"y":@(0),@"w":@(1),@"h":@(3)},
@{@"x":@(1),@"y":@(0),@"w":@(2),@"h":@(2)},
@{@"x":@(1),@"y":@(2),@"w":@(2),@"h":@(1)},
],
},
@{
@"rowNumber":@(3),
@"arrangeNumber":@(3),
@"itemCoordinaties":@[@{@"x":@(0),@"y":@(0),@"w":@(1),@"h":@(2)},
@{@"x":@(1),@"y":@(0),@"w":@(2),@"h":@(2)},
@{@"x":@(0),@"y":@(2),@"w":@(1),@"h":@(1)},
@{@"x":@(1),@"y":@(2),@"w":@(2),@"h":@(1)},
]
},];
return array;
}

Expand Down
3 changes: 3 additions & 0 deletions VILLOID/Layout/YYTemplateLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

@interface YYTemplateLayout : NSObject

@property (strong, nonatomic) NSNumber *rowNumber;
@property (strong, nonatomic) NSNumber *arrangeNumber;

@property (strong, nonatomic) NSArray<__kindof YYItemCoordinate *> *itemCoordinaties;

+ (NSArray <__kindof YYTemplateLayout *> *)yy_itemTemplateLayout;
Expand Down
6 changes: 4 additions & 2 deletions VILLOID/Layout/YYTemplateLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ @implementation YYTemplateLayout
NSMutableArray *array = [NSMutableArray array];

NSArray *layouts = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"layout" ofType:@"plist"]];
for (NSArray *layout in layouts) {
for (NSDictionary *layout in layouts) {
YYTemplateLayout *template = [[YYTemplateLayout alloc]init];
template.itemCoordinaties = [YYItemCoordinate yy_itemCoordinatesWithArray:layout];
template.itemCoordinaties = [YYItemCoordinate yy_itemCoordinatesWithArray:layout[@"itemCoordinaties"]];
template.rowNumber = layout[@"rowNumber"];
template.arrangeNumber = layout[@"arrangeNumber"];
[array addObject:template];
}
return array;
Expand Down
2 changes: 2 additions & 0 deletions VILLOID/View/YYTemplateView.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ - (void)initConfig {

- (void)setTemplateLayout:(YYTemplateLayout *)templateLayout {
_templateLayout = templateLayout;
_rowNumber = templateLayout.rowNumber.integerValue;
_arrangeNumber = templateLayout.arrangeNumber.integerValue;
[self createSubviews];
}

Expand Down
4 changes: 4 additions & 0 deletions VILLOID/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "ViewController.h"
#import "YYTemplateLayout.h"
#import "YYCollectionViewCell.h"
#import "YYLayoutDefine.h"

@interface ViewController ()<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

Expand All @@ -36,6 +37,9 @@ - (void)viewDidLoad {
[_collectionView registerClass:[YYCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
_collectionView.pagingEnabled = YES;
_collectionView.backgroundColor = [UIColor whiteColor];

NSArray *array = getLayoutDafines();
[array writeToFile:@"/Users/dongzhiyue/Desktop/layout.plist" atomically:YES];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
Expand Down
Loading

0 comments on commit df19f13

Please sign in to comment.