我正在尝试向UICollectionView
添加一个UIRefreshControl
,但问题是,除非集合视图填满其父容器的高度,否则刷新控件不会出现。换句话说,除非集合视图足够长而需要滚动,否则无法向下拖动以显示刷新控件视图。一旦集合超过其父容器的高度,它就会被拉下并显示刷新视图。
我已经设置了一个快速的iOS项目,在主视图中只有一个UICollectionView
,还有一个指向集合视图的出口,这样我就可以在viewDidLoad
中向其中添加UIRefreshControl
。还有一个具有重用标识符cCell
的原型单元
这就是控制器中的所有代码,它很好地演示了这个问题。在这段代码中,我将单元格的高度设置为100,这不足以填充显示,因此视图不能被拉出,刷新控件也不会显示。将其设置为更高的值以填充显示屏,然后它就可以工作了。有什么想法吗?
@interface ViewController () <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
@property (strong, nonatomic) IBOutlet UICollectionView *collectionView;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[self.collectionView addSubview:refreshControl];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 1;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
return [collectionView dequeueReusableCellWithReuseIdentifier:@"cCell" forIndexPath:indexPath];
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(self.view.frame.size.width, 100);
}
https://stackoverflow.com/questions/14678727
复制相似问题