8

I have a UICollectionView with a custom UICollectionViewCell. The UICollectionView scrolls horizontally, with each cell occupying all of the visible screen.

The UICollectionViewCell has a UIView subview, which in turn has a UIScrollView subview.

The UIScrollView is intended to scroll vertically, but it's not scrolling at all. I've tried setting the scroll view's contentSize with no success.

I suspect that the UIScrollView is not getting any touch events rather than it being a size issue.

Any suggestions?

EDIT >>

I'm now sure it's an event problem rather than anything specific to the UIScrollView.

I've now overridden the pointInside: method in the UIView in the UICollectionViewCell and can see that it now returns false every time I tap on it. In that case you'd think that the tap event would propagate to the next subview , but the UIView still isn't getting events. I've tried adding a UIGestureRecognizer to the UIView but it never registers a tap.

Could there be anything here intercepting the events that I'm not aware of?

jszumski
  • 7,430
  • 11
  • 40
  • 53
Phil John
  • 1,225
  • 1
  • 15
  • 24

4 Answers4

1

I've been trying to solve a similar problem with a scrollview, and your edit about events reminded me of this question (which solved my problem again) How can I use a UIButton in a UICollection supplementary view?

Its possible you need to be using a UICollectionReusableView, not a UICollectionViewCell. Changing the class worked for me because I was using a button (and recently a scrollview) in a header.

However I've not tried for cells themselves. For capturing events from a UICollectionViewCell, maybe the following may help? Getting button action : UICollectionView Cell

Community
  • 1
  • 1
JonLord
  • 807
  • 10
  • 24
0

Try to disable userInteractionEnabled for the UIView and enable it for your UIScrollView

Yaman
  • 3,949
  • 4
  • 38
  • 60
  • Thanks, but that doesn't solve the problem. Also, I occasionally load the UIView/UIScrollView outside of the CollectionView. When I disable userInteractionEnabled on the UIView and enable it on the UIScrollView, I don't get any scrolling there either. – Phil John Feb 07 '13 at 15:43
0

I'm not sure if this was your problem, but it was mine - and I'm putting it here in case anyone else comes across this for the same reason. I wanted to put a UIScrollView inside a UICollectionReusableView but by accident I had created my custom class as;

class CustomCellHeader: UICollectionViewCell {


}

instead of;

class CustomCellHeader: UICollectionReusableView {


}

Once I changed that, the UIScrollView within my header cell came to life!

J.C
  • 1,409
  • 2
  • 19
  • 32
0
  1. Embed the scrollable content in a ScrollView within the cell.
  2. Add "UICollectionViewDelegateFlowLayout" to the UICollectionViewCell i.e.:

    class SomeCollectionCell: UICollectionViewCell, UICollectionViewDelegateFlowLayout {
    }

Now scrolling within the cell should work.

Claytog
  • 618
  • 8
  • 8