scrollView的ContentSize自适应

- (void)reloadScrollViewContentSizeWithScrollView:(UIScrollView *)scrollView {
    NSMutableArray * arr = [NSMutableArray array];
    [[scrollView subviews] enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [arr addObject:@(CGRectGetMaxY(obj.frame))];
    }];
    
    for (int i = 0; i < arr.count-1; i++) {
        CGFloat aaa = [arr[i] doubleValue];
        CGFloat bbb = [arr[i+1] doubleValue];
        if (aaa > bbb) {
            [arr exchangeObjectAtIndex:i withObjectAtIndex:i+1];
        }
    }
    NSLog(@"%lf", [[arr lastObject] doubleValue]);
    [scrollView setContentSize:CGSizeMake(0, [[arr lastObject] doubleValue])];
}

你可能感兴趣的:(ios)