supersr--九宫格公式(根据多少行多少列排版)
- (void)layoutSubviews{
[super layoutSubviews];
NSUInteger count = self.subviews.count;
NSInteger maxC = 3;
CGFloat childViewWH = (SCREENW - 2 * MARGIN) / maxC;
for (int i = 0; i < count; i++) {
// 拿到子控件调整位置
UIView *view = self.subviews[i];
view.size = CGSizeMake(childViewWH, childViewWH);
// 求出其在第几行第几列
NSInteger col = i % maxC;
NSInteger row = i / maxC;
if (view.x == 0 && view.y == 0) {
view.x = col * (childViewWH + MARGIN);
view.y = row * (childViewWH + MARGIN);
}else{
[UIView animateWithDuration:0.25 animations:^{
view.x = col * (childViewWH + MARGIN);
view.y = row * (childViewWH + MARGIN);
}];
}
}
}