【问题标题】:Scroll a UICollectionView when scrolling on a UIButton over it在 UIButton 上滚动时滚动 UICollectionView
【发布时间】:2016-06-04 05:44:11
【问题描述】:

我有一个带有水平 UICollectionView 和两个 UIButton 的视图(固定在右侧和左侧,屏幕宽度为 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];
    }
}

我该怎么办?

谢谢。

【问题讨论】:

    标签: ios objective-c uibutton uicollectionview


    【解决方案1】:

    子类collectionView并覆盖

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

    }

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-28
      • 1970-01-01
      • 1970-01-01
      • 2013-03-08
      • 1970-01-01
      • 1970-01-01
      • 2020-06-10
      • 1970-01-01
      相关资源
      最近更新 更多