iOS 6.0: UICollectionView doesn't respect clipsToBounds with pagingEnabled

后端 未结 4 1326
太阳男子
太阳男子 2021-02-06 07:37

Background

I am implementing a UICollectionView (for the first time) in an effort to achieve a paged horizontal scroll view of tiles. I\'d

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-06 08:29

    You'll want to also override -pointInside:withEvent: to allow scroll gestures to start outside the frame of the collection view. I do this using a UIEdgeInsets property in my collection view subclass:

    - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
        CGRect extendedBounds = UIEdgeInsetsInsetRect(self.bounds, self.touchAreaInsets);
    
        return CGRectContainsPoint(extendedBounds, point);
    }
    

    If you don't need App Store safety, you can override _visibleBounds to avoid negative spacing hacks:

    - (CGRect)_visibleBounds {
         return UIEdgeInsetsInsetRect(self.bounds, self.touchAreaInsets);
    }
    

    If you're not too pressed on code size and need App Store safety you could also subclass PSTCollectionView and possibly override visibleBoundRects for the same effect.

提交回复
热议问题