ios - 在 UIButton 上滚动时滚动 UICollectionView

标签 ios objective-c uibutton uicollectionview

我有一个带有水平 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/

相关文章:

iphone - iOS:如何使用下载的 CSV 填充 CoreData

ios - 如何创建一个只有屏幕一半高度的 ViewController?

objective-c - UIViewController purgeMemoryForReason : Crashing on iOS 5

ios - 回复 : How Do I Make A Count For The Amount Of Times A Certain URL Was Open From A Different Web View?

cocoa-touch - 标题未显示为 UIButton

ios - 在推送新的 View Controller 之前移除键盘

ios - 在钢琴应用程序中演奏声音的最佳方式是什么?

iphone - 组合标签、 TextView 和图像(但图像与文本滚动)

ios - Xcode 7 Swift 2 我应该使用按钮字体还是图像?

ios - UICollectionViewCell 中的按钮在单击时发出键盘声音