防止UICollectionView子视图滚动

时间:2015-05-22 06:11:38

标签: ios uicollectionview uicollectionviewcell subview sticky-footer

我正在使用UICollectionView。从来没有合作过  这之前。所以,我面临很多问题。一个是我想添加  UIView作为UICollectionView的子视图,用于展示  UIView作为弹出视图点击UICollectionViewCell。我能够添加  子视图collectionView。但问题是当我滚动时  UICollectionView,子视图也随之滚动。它需要UIView  坚持在UICollectionView的底部。它不应该滚动 UICollectionView。它应始终在视图底部可见。一世  试图添加UIView作为页脚,但没有奏效。

这是我的代码  footerView

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"add footer view ");
    UICollectionReusableView *reusableview = nil;

    if (kind == UICollectionElementKindSectionFooter) {
        UICollectionReusableView *footerview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:UICollectionElementKindSectionFooter forIndexPath:indexPath];
        [footerview addSubview:popupView];

        reusableview = footerview;
    }

    return reusableview;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
{
    return CGSizeMake(dotsCollectionView.frame.size.width, 120);
}

如果还有其他办法,请建议我。任何帮助,将不胜感激。谢谢

1 个答案:

答案 0 :(得分:0)

UIView不应该是UICollectionView的子视图。它应该是UICollectionView的兄弟姐妹,它将占据父视图的下半部分。如果您希望UIView仅在用户选择单元格时可见,您可以使用UIView的高度约束(假设您已添加它)。将高度约束常量设置为用户选择单元格时所需的值,并在希望隐藏时将其设置为0。

相关问题