美文网首页
扩大UISlider滑块的触摸区域

扩大UISlider滑块的触摸区域

作者: 异乡人_4f2a | 来源:发表于2021-02-20 19:47 被阅读0次

#define thumbBound_x 10

#define thumbBound_y 20

@interface MGSlider:UISlider 

@property (nonatomic, assign) CGRect  lastBounds;

@end

@implementation MGSlider

//MARK:扩大滑块的触摸区域

- (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rectvalue:(float)value {

    rect.origin.x= rect.origin.x;

    rect.size.width= rect.size.width;

    CGRectresult = [super thumbRectForBounds:bounds trackRect:rect value:value];

    lastBounds= result;

    return result;

}

- (UIView*)hitTest:(CGPoint)pointwithEvent:(UIEvent*)event{

    UIView*result = [super hitTest:pointwithEvent:event];

    if(point.x<0|| point.x>self.bounds.size.width){

      returnresult;

    }

    if((point.y>= -thumbBound_y) && (point.y

            floatvalue =0.0;

            value = point.x-self.bounds.origin.x;

            value = value/self.bounds.size.width;

            value = value <0?0: value;

            value = value >1?1: value;

            value = value * (self.maximumValue-self.minimumValue) +self.minimumValue;

//            [self setValue:value animated:YES];

    }

    return result;

}

- (BOOL)pointInside:(CGPoint)pointwithEvent:(UIEvent*)event{

    BOOL result = [super pointInside:pointwithEvent:event];

    if(!result && point.y> -10) {

        if((point.x>=lastBounds.origin.x-thumbBound_x) && (point.x<= (lastBounds.origin.x+lastBounds.size.width+thumbBound_x)) && (point.y< (lastBounds.size.height+thumbBound_y))) {

            result =YES;

        }

    }

      return result;

}

@end

相关文章

网友评论

      本文标题:扩大UISlider滑块的触摸区域

      本文链接:https://www.haomeiwen.com/subject/bcuxfltx.html