我有一个带有水平 UICollectionView 和两个 UIButton 的 View (固定在右侧和左侧,屏幕宽度为 25%)。
我的需要是在我开始拖动按钮时滚动 collectionView 而不会松开按钮的点击手势。
我试图覆盖我的按钮的 touchesMoved 并将触摸和事件发送到我的 collectionView 但它不起作用。
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
if (self.delegate && [self.delegate respondsToSelector:@selector(buttonDidTouchesMoved:withEvent:)]) {
[self.delegate buttonDidTouchesMoved:touches withEvent:event];
}
}
我该怎么做?
谢谢。
最佳答案
子类collectionView并覆盖
- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
if ([view isKindOfClass:UIButton.class]) {
return YES;
}
return [super touchesShouldCancelInContentView:view];
这解决了我的问题而无需松开按钮点击。
关于ios - 在 UIButton 上滚动时滚动 UICollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35559734/