0
我有自定義雙滑塊的問題。有兩個圖像是拇指。應用程序工作正常,兩個拇指可以用兩個手指移動,但突出顯示有問題。如何使用多點觸控正確顯示兩張圖像的高光?
當我從一個拇指脫下手指時,從第二個拇指突出顯示也恢復正常。當我使用任何if
和else
陳述時,它會帶來另一個不好的結果:有時在手指從圖像移出時突出顯示不變或保持不變。或眨眼。
我不知道,如何繼續工作,綁定高亮與endTouches事件正常。如果沒有按下,則不要突出顯示拇指。如何解決?
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for(UITouch *touch in [event allTouches]) {
CGPoint touchPoint = [touch locationInView:self];
if(CGRectContainsPoint(thumbLeft.frame, touchPoint)){
thumbLeft.highlighted = YES;
}
if(CGRectContainsPoint(thumbRight.frame, touchPoint)){
thumbRight.highlighted = YES;
}
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
//No idea here
for(UITouch *touch in [event allTouches]) {
CGPoint touchPoint = [touch locationInView:self];
//----------- ???? ----------//
thumbRight.highlighted = NO;
thumbLeft.highlighted = NO;
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
for(UITouch *touch in [event allTouches]) {
CGPoint touchPoint = [touch locationInView:self];
if (CGRectContainsPoint(thumbLeft.frame, touchPoint)){
thumbLeft.center = CGPointMake(MAX(barLeftHorizontalPosition, MIN(touchPoint.x, thumbRight.center.x - minimumRange)), thumbLeft.center.y);
thumbLeft.highlighted = YES;
valueLeft = [self valueGetX:thumbLeft.center.x];
}
if (CGRectContainsPoint(thumbRight.frame, touchPoint)){
thumbRight.center = CGPointMake(MAX(thumbLeft.center.x + minimumRange, MIN(touchPoint.x, barRightHorizontalPosition)), thumbRight.center.y);
thumbRight.highlighted = YES;
valueRight = [self valueGetX:thumbRight.center.x];
}
[self sendActionsForControlEvents:UIControlEventValueChanged];
}
}