0

Webを検索しましたが、明確な答えが見つかりませんでした。panGestureRecognizerを使用してx軸のスライダーボタンをドラッグしますが、スライダートラックの外側にある場合はドラッグできないようにします。私はなんとか何かをすることができましたが、それは実際にはうまくいきません。これが私のコードです

-(void) handleDrag:(UIPanGestureRecognizer*)panGestureRecognizer
{

    if (panGestureRecognizer.state==UIGestureRecognizerStateBegan)
    {

    }
    if (panGestureRecognizer.state==UIGestureRecognizerStateChanged)
    {
        CGPoint touchPoint=[panGestureRecognizer locationOfTouch:0  inView:self];
        if (sliderButton.center.x > first.center.x-0.5f && sliderButton.center.x-0.5f < third.center.x && CGRectContainsPoint(sliderButton.frame, touchPoint) )  // if we are still in the slidertrack and the touch is on the sliderbutton
        {
            CGPoint newPoint=CGPointMake(touchPoint.x+0.5,sliderButton.center.y);
            sliderButton.center=newPoint;
        }

    }
} 

これは私のスライダーです ここに画像の説明を入力してください

最初のボタンは「木」、2番目のボタンは「金」、3番目のボタンは「土」です。スライダーボタンをこれらの境界内でのみ移動させたい。

ありがとうございました。

4

0 に答える 0