Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIRefreshControl未以contentInset集为中心_Ios_Objective C_Uicollectionview_Uirefreshcontrol - Fatal编程技术网

Ios UIRefreshControl未以contentInset集为中心

Ios UIRefreshControl未以contentInset集为中心,ios,objective-c,uicollectionview,uirefreshcontrol,Ios,Objective C,Uicollectionview,Uirefreshcontrol,我已将刷新控件添加到集合视图中。一切正常,但当我设置collectionView.contentInset=UIEdgeInsetsMake(0,20,20,20)时,刷新控件的宽度保持不变,但移动了20px,因此不在视图中居中。控制应减少40px,以使其正确 self.collectionView = [[UICollectionView alloc] initWithFrame:rect collectionViewLayout:flowLayout]; self.collectionVie

我已将刷新控件添加到集合视图中。一切正常,但当我设置collectionView.contentInset=UIEdgeInsetsMake(0,20,20,20)时,刷新控件的宽度保持不变,但移动了20px,因此不在视图中居中。控制应减少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 action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
[self.collectionView addSubview:pullDownRefresh];
我尝试在添加视图(也在viewWillLayoutSubviews中)后手动设置宽度,并尝试使用autoresizingMask,但没有效果


有什么想法吗?我想我需要把它放在一个容器视图中…但不需要

好,通过不设置collectionView.contentInset修复了该问题。相反,我设置了flowLayout

i、 e


接受的答案不符合我的需要,因为我有一个复杂的collectionView,有多种类型的单元格,每个单元格都有特定的部分插入,所以我不想在这个解决方案中钻研并增加复杂性

对我有效的方法很简单。将
UIRefreshControl
添加到
collectionView
的背景视图中:

collectionView.backgroundView = viewModel.refreshControl
完成刷新时,只需执行以下操作:

DispatchQueue.main.async {
    self.viewModel.refreshControl?.endRefreshing()
}

如果未添加到滚动视图中,容器视图将不会像UIRefreshControl断言的那样工作!节省了很多时间。
DispatchQueue.main.async {
    self.viewModel.refreshControl?.endRefreshing()
}