w内部的UICollectionView的didSelectIt

w内部的UICollectionView的didSelectIt

本文介绍了不会调用UIScrollView内部的UICollectionView的didSelectItemAtIndexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在UIscrollview内实现了不可滚动的UICollectionView .滚动视图的大小为100x100 ,集合视图的尺寸为100x200 ;滚动视图的内容大小为100x200.

I've implemented non scrollable UICollectionView inside a UIscrollview.The size of the scrollview is 100x100 and that of collection view is 100x200;And the content size of the scroll view is 100x200.

我的问题是,当我触摸某些单元格(100x100矩形中的单元格)时,没有调用 didSelectItemAtIndexPath .

My problem is, the didSelectItemAtIndexPath is not getting called when I touch some cells (the cells out of the 100x100 rect).

启用了单元的用户交互.当我将滚动视图的高度增加到等于集合视图的高度时,所有单元格都是可触摸的.预先感谢.

User interaction of the cells are enabled. All cells are touchable when I increment the scrollview height equal to the height of the collection view.Thanks in advance.

推荐答案

因为scrollView与Cell重叠...最好的方法是在UIScrollView上添加水龙头手势,例如

Because scrollView overlapped on Cell... Best way is add tap Gesture on UIScrollView such like,

UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureAction:)];
[recognizer setNumberOfTapsRequired:1];
self.scrollViu.userInteractionEnabled = YES;
[self.scrollViu addGestureRecognizer:recognizer];

在cellForItemAtIndexPath方法中添加上述代码,并编写诸如此类的手势操作方法

Add above code in cellForItemAtIndexPath method and Write gesture action method such like

-(void)gestureAction:(UITapGestureRecognizer *) sender
{
    CGPoint touchLocation = [sender locationOfTouch:0 inView:self.YourCollectionViewName];
    NSIndexPath *indexPath = [self.YourCollectionViewName indexPathForRowAtPoint:touchLocation];

    NSLog(@"%d", indexPath.item);
}

在上述手势(操作)方法中,您可以获得与didSelectItemAtIndexPath相同的indexPath.

Here in above gesture (action) method you can get indexPath as same as didSelectItemAtIndexPath.

这篇关于不会调用UIScrollView内部的UICollectionView的didSelectItemAtIndexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 09:21