UICollectionView clipsToBounds is not working prop

2019-09-07 06:12发布

问题:

I am using UICollectionView with horizontal paging enabled.
My collectionView frame is less than the screen size.

I used the following code :

myCollectionView.clipsToBounds=FALSE;

Still I am not able to see the views outside the bounds of my collectionView. I am using custom UICollectionViewLayout

回答1:

If the size of each page is greater or equal to your collectionView's frame size, you will not be able to see the content outside the frame even clipToBounds is disabled.

In order to save the memory, the cells in the collectionView are reusable and will be removed if they are out of the frame (i.e. only shows the visible cells).

To recreate the effects like the one seen on the App Store:

Try to set the frame of the collectionView as large as your collectionView's superView, and specify proper minimumLineSpacing for your UICollectionViewFlowLayout.

You may like to take a look at this post about targetContentOffsetForProposedContentOffset:withScrollingVelocity which gives you controls to decide the contentOffset of a given page.



回答2:

I'm not sure but may be the problem when you init your collectionView it's initializing with the some default settings like clipToBounds. Try this method to layout subviews:

-(void)layoutSubviews{
   [super layoutSubviews];
   myCollectionView.clipsToBounds = FALSE;
}

Hope it works.