Reputation: 1237
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?
Upvotes: 8
Views: 3084
Reputation: 967
Add "UICollectionViewDelegateFlowLayout" to the UICollectionViewCell i.e.:
class SomeCollectionCell: UICollectionViewCell, UICollectionViewDelegateFlowLayout {
}
Now scrolling within the cell should work.
Upvotes: 0
Reputation: 1439
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!
Upvotes: 0
Reputation: 817
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
Upvotes: 1
Reputation: 3991
Try to disable userInteractionEnabled
for the UIView
and enable it for your UIScrollView
Upvotes: 0