scrollerView 和 slider 的滑动事件冲突的解决方案

// - 方案一

-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{

    if (CGRectContainsPoint(self.subView.frame, point)) {
        self.scrollEnabled = NO;
        return YES;
    }
    self.scrollEnabled = YES;
    return YES;
}
 

 

// - 方案二

-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
    if (CGRectContainsPoint(self.subView.frame, point)) {
        self.scrollEnabled = NO;
        return [super hitTest:point withEvent:event];
    }
    self.scrollEnabled = YES;
    return [super hitTest:point withEvent:event];
}

 

// - 设置 scrollview 做的选项卡的 view 在第一个选项上是可以左滑返回

-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{

    if ([[super hitTest:point withEvent:event] isKindOfClass:[UIControl class]]

        ) {

        return [super hitTest:point withEvent:event];

    }else{

        if ((self.contentOffset.x == 0) && (point.x < 30)) {

            return nil;

        }

         return [super hitTest:point withEvent:event];

    }

}

// - 设置事件可以穿透 view

@implementation DYContainerBgView

/** 可以透过事件 */

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{

    if ([super hitTest:point withEvent:event] == self) return nil;

    return [super hitTest:point withEvent:event];

}

@end

你可能感兴趣的:(scrollerView 和 slider 的滑动事件冲突的解决方案)