1

スワイプしたい3つのView Controllerを備えたスクロールビューがあります。ただし、ビュー コントローラーの 1 つに UIPanGestureRecognizer があり、スクロールビューが機能しなくなります。これはパンのコードです:

- (void)pan:(UIPanGestureRecognizer *)aPan; // When pan guesture is recognised
{
CGPoint location = [aPan locationInView:self.view]; // Location of finger on screen
CGRect secondRect = CGRectMake(210.0, 45.0, 70.0, 325.0); // Rectangles of maximimum bar area
CGRect minuteRect = CGRectMake(125.0, 45.0, 70.0, 325.0);
CGRect hourRect = CGRectMake(41.0, 45.0, 70.0, 325.0);

if (CGRectContainsPoint(secondRect, location)) { // If finger is inside the 'second' rectangle

    CGPoint currentPoint = [aPan locationInView:self.view];

    currentPoint.y -= 80;  // Make sure animation doesn't go outside the bars' rectangle

    if (currentPoint.y < 0) {
    currentPoint.y = 0;
    }
    else if (currentPoint.y > 239) {
    currentPoint.y = 239;
    }

    currentPoint.y = 239.0 - currentPoint.y;

    CGFloat pointy = currentPoint.y - fmod(currentPoint.y, 4.0);

    [UIView animateWithDuration:0.01f  // Animate the bars to rise as the finger moves up and down
                     animations:^{
                         CGRect oldFrame = secondBar.frame;
                         secondBar.frame = CGRectMake(oldFrame.origin.x, (oldFrame.origin.y - (pointy - secondBar.frame.size.height)), oldFrame.size.width, (pointy));
                     }];

    CGFloat result = secondBar.frame.size.height - fmod(secondBar.frame.size.height, 4.0);

    secondInt = (result / 4.0); // Update labels with new time

    self->secondLabel.text = [NSString stringWithFormat:@"%02d", secondInt];
}
}

基本的に、このコードにより、ユーザーは画面上で指を上下にドラッグし、uiview の高さを変更できます。したがって、これには上下のパン ジェスチャのみが必要で、スクロール ビューには左右のパン ジェスチャのみが必要です。

誰も私がこれを行う方法を知っていますか?

4

2 に答える 2

3

スクロールビューには panGestureRecognizer というプロパティがあります。独自の UIPanGestureRecognizer のデリゲートを作成し、このメソッドを実装できます。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {

    if(otherGestureRecognizer == myScrollView.panGestureRecognizer) {
         return YES;
    } else {
         return NO;
    }
}
于 2013-11-08T00:03:48.220 に答える
-1

UIPanGestureRecognizer- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch戻すことができるデリゲート メソッド、YESまたはNOパン ジェスチャがタッチを受け取らないようにする/防止するデリゲート メソッドが含まれています。

そのメソッド内で、次のように記述できます。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    CGPoint velocity = [gestureRecognizer velocityInView:yourView];

    if(velocity.x > 0)
    {
        NSLog(@"gesture went right"); // return NO
    }
    else if (velocity.x < 0)
    {
        NSLog(@"gesture went left"); // return NO
    }

    if (velocity.y > 0)
    {
        NSLog(@"gesture went down"); // return YES
    }
    else if (velocity.y < 0)
    {
        NSLog(@"gesture went up"); // return YES
    }
}

確かに、これはおそらく最もクリーンな実装ではありません。混合ジェスチャーのドアを開けたままにしています。そのため、必ず注意してください。

于 2013-11-07T22:00:46.793 に答える