OGeek|极客世界-中国程序员成长平台

标题: ios - 在 UIButton 上滚动时滚动 UICollectionView [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 14:47
标题: ios - 在 UIButton 上滚动时滚动 UICollectionView

我有一个带有水平 UICollectionView 和两个 UIButton 的 View (固定在右侧和左侧,屏幕宽度为 25%)。

当我开始拖动按钮时,我需要滚动 collectionView 而不会丢失按钮的点击手势。

我试图覆盖我的按钮的 touchesMoved 并将触摸和事件发送到我的 collectionView 但它不起作用。

- (void)touchesMovedNSSet<UITouch *> *)touches withEventUIEvent *)event {
    [super touchesMoved:touches withEvent:event];
    if (self.delegate && [self.delegate respondsToSelectorselector(buttonDidTouchesMoved:withEvent]) {
        [self.delegate buttonDidTouchesMoved:touches withEvent:event];
    }
}

我该怎么办?

谢谢。



Best Answer-推荐答案


子类collectionView并覆盖

- (BOOL)touchesShouldCancelInContentViewUIView *)view {
if ([view isKindOfClass:UIButton.class]) {
    return YES;
}
return [super touchesShouldCancelInContentView:view];

}

这解决了我的问题而不会丢失按钮点击。

关于ios - 在 UIButton 上滚动时滚动 UICollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35559734/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4