OStack程序员社区-中国程序员成长平台

标题: ios - UIRefreshControl 不以 contentInset 集为中心 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 15:58
标题: ios - UIRefreshControl 不以 contentInset 集为中心

我在 Collection View 中添加了一个刷新控件。一切正常,但是当我设置 collectionView.contentInset = UIEdgeInsetsMake(0, 20, 20, 20) 时,刷新控件的宽度保持不变,但移动了 20px,因此不在 View 中居中。控件应减少 40px 才能正确。

self.collectionView = [[UICollectionView alloc] initWithFrame:rect collectionViewLayout:flowLayout];
self.collectionView.contentInset = UIEdgeInsetsMake(0, 20, 20, 20)
UIRefreshControl* pullDownRefresh = [[UIRefreshControl alloc] init];
[pullDownRefresh addTarget:self actionselector(refresh forControlEvents:UIControlEventValueChanged];
[self.collectionView addSubview:pullDownRefresh];

我尝试在添加 View 后手动设置宽度(也在 viewWillLayoutSubviews 中),但使用 autoresizingMask 无济于事。

有什么想法吗?我想我需要将它放在容器 View 中......但不需要!



Best Answer-推荐答案


好的,通过不设置 collectionView.contentInset 解决了这个问题。相反,我设置了 flowLayout

flowLayout.sectionInset = UIEdgeInsetsMake(0, 20, 20, 20);

关于ios - UIRefreshControl 不以 contentInset 集为中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50952392/






欢迎光临 OStack程序员社区-中国程序员成长平台 (http://ostack.cn/) Powered by Discuz! X3.4