is stuck in a recursive layout loop. This can happen when self-sizing views do not return consistent

调试多个 collectionView 列表的时候,遇到如下一个报错

is stuck in a recursive layout loop. This can happen when self-sizing views do not return consistent sizes, or the collection view’s frame/bounds/contentOffset is being constantly adjusted. To debug this issue, check the Console app for logs in the “UICollectionViewFeedbackLoopDebugger” category.
Collection view: <LIVNumberSubSingleCollectionView: 0x177b42800; baseClass = UICollectionView; frame = (393 0; 393 852); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x175b40b10>; backgroundColor = UIExtendedSRGBColorSpace 0.941176 0.952941 0.968627 1; layer = <CALayer: 0x301a53b60>; contentOffset: {0, -394.33333333333331}; contentSize: {393, 0}; adjustedContentInset: {394.16667175292969, 0, 0, 0}; layout:

经过反复排查,发现是一个监听导致的,因为我在一个监听中去修改其他列表的偏移量,其他列表偏移量的变化又出发监听,出发自身偏移量的变化,又触发监听。导致了无尽的循环调用,代码如下


- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
    if ([keyPath isEqualToString:@"contentOffset"]) {
        UIScrollView *scrollView = (UIScrollView *)object;
        if (scrollView != nil) {
            [self listScrollViewDidScroll:scrollView];
        }
    }else if ([keyPath isEqualToString:@"contentSize"]) {
        UIScrollView *scrollView = (UIScrollView *)object;
        if (scrollView != nil) {
            CGFloat minContentSizeHeight = self.bounds.size.height - self.segmentedHeight - self.ceilPointHeight;
            CGFloat contentH = scrollView.contentSize.height;
            if (minContentSizeHeight > contentH && self.isHoldUpScrollView) {
                scrollView.contentSize = CGSizeMake(scrollView.contentSize.width, minContentSizeHeight);
                // 新的scrollView第一次加载的时候重置contentOffset
                if (self.currentListScrollView != nil && scrollView != self.currentListScrollView) {
                    if (!CGSizeEqualToSize(scrollView.contentSize, CGSizeZero)) {
                        [self setListScrollView:scrollView offset:CGPointMake(0, self.currentListInitializeContentOffsetY)];
                    }
                }
            }else {
                BOOL shouldReset = YES;
                for (id<LBPageSmoothListViewDelegate> list in self.listDict.allValues) {
                    if (list.listScrollView == scrollView && [list respondsToSelector:@selector(listScrollViewShouldReset)]) {
                        shouldReset = [list listScrollViewShouldReset];
                    }
                }
                
                if (minContentSizeHeight > contentH && shouldReset) {
                    [self setListScrollView:scrollView offset:CGPointMake(scrollView.contentOffset.x, -self.headerContainerHeight)];
                    [self listScrollViewDidScroll:scrollView];
                }
            }
        }
    }else {
        [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
    }
}


解决方法,不使用监听,一个列表滚动个的时候,外面直接调用代理方法修改其他列表的偏移量就好了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值