Mas*_*oud 6 ios uicollectionview
我试着子类UICollectionView和压倒一切的touchesBegan:withEvent:和hitTest:WithEvent:,当我触摸一个细胞都这些方法触发.但是,如果我触摸单元格之间的空间,则根本不会发生任何事情.这是我创造的:
@interface WSImageGalleryCollectionView : UICollectionView
@end
Run Code Online (Sandbox Code Playgroud)
..和..
@implementation WSImageGalleryCollectionView
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"Touches began");
[super touchesBegan:touches withEvent:event];
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
NSLog(@"Hit test reached");
return [super hitTest:point withEvent:event];
}
@end
Run Code Online (Sandbox Code Playgroud)
注意:手势识别器似乎有完全相同的问题,这就是为什么我尝试使用touchesBegan进行更低级别的操作.
小智 12
您只需将视图设置为背景视图,然后就可以添加手势识别器:
collectionView.backgroundView = [[UIView alloc] init];
[collectionView.backgroundView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnBackgroundRecognized)]];
Run Code Online (Sandbox Code Playgroud)
您一定有其他东西阻止了touchesBegan发射。
子类化UICollectionView并在 a 内部使用该子类UICollectionViewController将允许您检测 中单元格之间的点击touchesBegan。
我刚刚通过修改Apple的CollectionView-simple示例进行了尝试 。
| 归档时间: |
|
| 查看次数: |
1794 次 |
| 最近记录: |