擴(kuò)大UISlider滑塊的觸摸區(qū)域

#define thumbBound_x 10

#define thumbBound_y 20

@interface MGSlider:UISlider?

@property (nonatomic, assign) CGRect ?lastBounds;

@end


@implementation MGSlider


//MARK:擴(kuò)大滑塊的觸摸區(qū)域

- (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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容