Closed DolphinsLoveCats closed 7 years ago
您好,在次打扰 我对与demoVC2.m中 此方法有疑惑
// 设置一排固定间距自动宽度子view [self setupAutoWidthViewsWithCount:4 margin:10];
进入方法
// 设置一排固定间距自动宽度子view - (void)setupAutoWidthViewsWithCount:(NSInteger)count margin:(CGFloat)margin { _autoWidthViewsContainer = [UIView new]; _autoWidthViewsContainer.backgroundColor = [UIColor greenColor]; [self.view addSubview:_autoWidthViewsContainer]; NSMutableArray *temp = [NSMutableArray new]; for (int i = 0; i < count; i++) { UIView *view = [UIView new]; view.backgroundColor = [UIColor orangeColor]; [_autoWidthViewsContainer addSubview:view]; view.sd_layout.autoHeightRatio(0.4); // 设置高度约束 [temp addObject:view]; } _autoWidthViewsContainer.sd_layout .leftSpaceToView(self.view, 10) .rightSpaceToView(self.view, 10) .topSpaceToView(_centerButton, 10); // 此步设置之后_autoWidthViewsContainer的高度可以根据子view自适应 [_autoWidthViewsContainer setupAutoWidthFlowItems:[temp copy] withPerRowItemsCount:4 verticalMargin:margin horizontalMargin:margin verticalEdgeInset:5 horizontalEdgeInset:10]; }
此段代码中最后一段
// 此步设置之后_autoWidthViewsContainer的高度可以根据子view自适应 [_autoWidthViewsContainer setupAutoWidthFlowItems:[temp copy] withPerRowItemsCount:4 verticalMargin:margin horizontalMargin:margin verticalEdgeInset:5 horizontalEdgeInset:10];
我进入看具体的实现方法,发现 这个高度的取值仅仅是取到的数组内最后一个view的,[self setupAutoHeightWithBottomView:viewsArray.lastObject bottomMargin:vInset];但是在此 _autoWidthViewsContainer的view的高度如果都不固定,那么是不是应该取数组内最高的一个呢?而不是最后的一个,方法如下:UIView+SDAutoLayout.m 内.
[self setupAutoHeightWithBottomView:viewsArray.lastObject bottomMargin:vInset];
_autoWidthViewsContainer
view
UIView+SDAutoLayout.m
- (void)setupAutoWidthFlowItems:(NSArray *)viewsArray withPerRowItemsCount:(NSInteger)perRowItemsCount verticalMargin:(CGFloat)verticalMargin horizontalMargin:(CGFloat)horizontalMagin verticalEdgeInset:(CGFloat)vInset horizontalEdgeInset:(CGFloat)hInset { self.sd_categoryManager.flowItems = viewsArray; self.sd_categoryManager.perRowItemsCount = perRowItemsCount; self.sd_categoryManager.verticalMargin = verticalMargin; self.sd_categoryManager.horizontalMargin = horizontalMagin; self.verticalEdgeInset = vInset; self.horizontalEdgeInset = hInset; self.sd_categoryManager.lastWidth = 0; if (viewsArray.count) { //这里仅仅去取最后一个高度是不是有问题? 应该遍历view后选择最高的把,这样这个高度才能是对的 [self setupAutoHeightWithBottomView:viewsArray.lastObject bottomMargin:vInset]; } else { [self clearAutoHeigtSettings]; } }
望采纳.
之前主要考虑用于展示等宽高的一组view;如果需要实现高度不同的一组view可以换用setupAutoHeightWithBottomViewsArray:高度自适应方法,这个方法会多出一些遍历和高度比较的操作,如果有需求可以用setupAutoHeightWithBottomViewsArray:自己简单封装一套api
您好,在次打扰 我对与demoVC2.m中 此方法有疑惑
进入方法
此段代码中最后一段
我进入看具体的实现方法,发现 这个高度的取值仅仅是取到的数组内最后一个view的,
[self setupAutoHeightWithBottomView:viewsArray.lastObject bottomMargin:vInset];
但是在此_autoWidthViewsContainer
的view
的高度如果都不固定,那么是不是应该取数组内最高的一个呢?而不是最后的一个,方法如下:UIView+SDAutoLayout.m
内.望采纳.