0

ユーザーが定規を動かしてUITableViewをスクロールできるようにするアプリケーションに取り組んでいます。現時点では、UITableView の行のみに移動を制限したいことを除いて、ルーラーは問題なく移動します。残念ながら、現時点では、ユーザーはテーブル全体を上からスクロールして、テーブルの下部を超えて画面の下部までスクロールできます。これを示すために画像を添付しました:

ここに画像の説明を入力

私が持っている関連コードは次のとおりです。

    - (void)panGestureDetected:(UIPanGestureRecognizer *)recognizer {

    CGPoint newCenter  = _imageView.center;

        newCenter.y = [recognizer locationInView:[_imageView superview]].y;

        if (newCenter.y - _imageView.frame.size.height / 2 < self.table.frame.origin.y)
            newCenter.y = self.table.frame.origin.y + _imageView.frame.size.height / 2;

        else if (newCenter.y + _imageView.frame.size.height / 2 > self.table.frame.origin.y + self.table.frame.size.height)
            newCenter.y = self.table.frame.origin.y + self.table.frame.size.height - _imageView.frame.size.height / 2;

        _imageView.center = newCenter;


        if ([recognizer state] == UIGestureRecognizerStateChanged) {

            if (newCenter.y == self.table.frame.origin.y + _imageView.frame.size.height / 2) {

                CGPoint topPoint = [recognizer locationInView:_table];
                NSIndexPath *nextRow = [_table indexPathForRowAtPoint:topPoint];
                int currentRow = nextRow.row;

                if (currentRow != 0) {

                    nextRow = [NSIndexPath indexPathForRow:currentRow-- inSection:0];

                    [UIView animateWithDuration:.3 animations:^{
                        [_table selectRowAtIndexPath:nextRow animated:NO scrollPosition:UITableViewScrollPositionBottom];

                    }];

                }


            }
            //below is the specific section where I believe is the issue
            else if (newCenter.y == self.table.frame.origin.y + self.table.frame.size.height - _imageView.frame.size.height / 2) {

                CGPoint bottomPoint = [recognizer locationInView:_table];
                NSIndexPath *nextRow = [_table indexPathForRowAtPoint:bottomPoint];
                int currentRow = nextRow.row;

                if (currentRow != [self.tireCode count]-1) {

                    nextRow = [NSIndexPath indexPathForRow:currentRow++ inSection:0];

                    [UIView animateWithDuration:.3 animations:^{
                        [_table selectRowAtIndexPath:nextRow animated:NO scrollPosition:UITableViewScrollPositionBottom];

                    }];

                }

            }

        }

私が言ったように、ルーラーは UITableView の行だけをスクロールし、それ以上はスクロールしないようにしたいと思います。私が間違っているのは何ですか?

4

1 に答える 1

0

範囲外の値を割り当てる前に、newCenter.y の値を確認する必要があります。最小値と最大値を定義します。

float calculatedY = self.table.frame.origin.y + _imageView.frame.size.height / 2;

calculatedY = MAX(calculatedY, MINIMUM_VALUE_HERE);
calculatedY = MIN(calculatedY, MAXIMUM_VALUE_HERE);

newCenter.y = calculatedY;
于 2013-09-23T20:47:09.500 に答える