Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用多点触摸正确显示两幅图像的高光?_Ios_Multi Touch_Uislider - Fatal编程技术网

Ios 如何使用多点触摸正确显示两幅图像的高光?

Ios 如何使用多点触摸正确显示两幅图像的高光?,ios,multi-touch,uislider,Ios,Multi Touch,Uislider,我对自定义双滑块有问题。有两个图像是拇指。应用程序工作正常,两个拇指都可以用两个手指移动,但突出显示有问题 当我从一个拇指上取下手指时,从第二个拇指上突出显示的也会恢复正常。当我使用任何if和elsestation时,它会带来另一个不好的结果:当手指从图像中移出时,有时会高亮显示not changes或停留。或者眨眼 我不知道如何继续工作,用EndTouchs事件正确绑定突出显示。若未按下,则不突出显示拇指。如何解决 -(void)touchesBegan:(NSSet *)touches wi

我对自定义双滑块有问题。有两个图像是拇指。应用程序工作正常,两个拇指都可以用两个手指移动,但突出显示有问题

当我从一个拇指上取下手指时,从第二个拇指上突出显示的也会恢复正常。当我使用任何
if
else
station时,它会带来另一个不好的结果:当手指从图像中移出时,有时会高亮显示not changes或停留。或者眨眼

我不知道如何继续工作,用EndTouchs事件正确绑定突出显示。若未按下,则不突出显示拇指。如何解决

-(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];
    }
}

我认为问题不在于
touchesend
,而在于
touchesMoved
方法

您应该将逻辑重新实现到touchesEnded中:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    for(UITouch *touch in [event allTouches]) {
        CGPoint touchPoint = [touch locationInView:self];
        if(CGRectContainsPoint(thumbLeft.frame, touchPoint)){
            thumbLeft.highlighted = NO;
        }
        if(CGRectContainsPoint(thumbRight.frame, touchPoint)){
            thumbRight.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];
        } else {
            thumbLeft.highlighted = NO;
        }

        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];
        } else {
            thumbRight.highlighted = NO;
        }

        [self sendActionsForControlEvents:UIControlEventValueChanged];
    }
}