148

を に追加しようとしてUIRefreshControlUICollectionViewますが、問題は、コレクション ビューが親コンテナーの高さを埋めない限り、更新コントロールが表示されないことです。つまり、コレクション ビューがスクロールを必要とするほど長くない限り、プルダウンして更新コントロール ビューを表示することはできません。コレクションがその親コン​​テナーの高さを超えるとすぐに、コレクションが引き下げられ、更新ビューが表示されます。

メインビューの内側だけで簡単なiOSプロジェクトをセットアップしUICollectionView、コレクションビューへのアウトレットを使用して、に追加できるようにUIRefreshControlしましたviewDidLoad。再利用識別子を持つプロトタイプセルもあります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);
}
4

7 に答える 7

403

これを試して:

self.collectionView.alwaysBounceVertical = YES;

の完全なコードUIRefreshControl

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.tintColor = [UIColor grayColor];
[refreshControl addTarget:self action:@selector(refershControlAction) forControlEvents:UIControlEventValueChanged];
[self.collectionView addSubview:refreshControl];
self.collectionView.alwaysBounceVertical = YES;
于 2013-02-04T18:59:33.050 に答える
30

属性/スクロール ビュー/ストーリーボードで垂直にバウンス/Xib

ここに画像の説明を入力

于 2013-12-13T09:04:07.267 に答える