【发布时间】:2014-06-19 07:44:14
【问题描述】:
我正在使用UICollectionView 来展示一些产品。在自定义UICollectionViewCell中,有一个自定义UIScrollView,里面有一些图片可以让用户快速预览。
要将轻按手势从UIScrollView 转发到UICollectionViewCell,我将覆盖与触摸相关的方法,如下所示:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.dragging) {
NSLog(@"Began ==>");
[self.nextResponder touchesBegan:touches withEvent:event];
}
else {
[super touchesBegan:touches withEvent:event];
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.dragging) {
NSLog(@"Moved ==>");
[self.nextResponder touchesMoved:touches withEvent:event];
}
else {
[super touchesMoved:touches withEvent:event];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.dragging) {
NSLog(@"Ended ==>");
[self.nextResponder touchesEnded:touches withEvent:event];
}
else {
[super touchesEnded:touches withEvent:event];
}
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.dragging) {
NSLog(@"Cancelled ==>");
[self.nextResponder touchesCancelled:touches withEvent:event];
}
else {
[super touchesCancelled:touches withEvent:event];
}
}
有时它在某些情况下不起作用。例如,第一次加载UICollectionView时,点击时可以调用didSelectItemAtIndexPath方法,但滚动或点击后,不再调用该方法,即使您尝试重新加载UICollectionView,也是还是行不通。
我尝试在UICollectionViewCell 的触摸方法中记录消息,触摸和事件被转发。但是,如果单元格获得手势,为什么会调用UICollectionView 的didSelectItemAtIndexPath 呢?
任何建议将不胜感激。
更新:
1.UICollectionViewCell是从nib文件中加载的。
【问题讨论】:
标签: ios uiscrollview uicollectionview uicollectionviewcell uiresponder