1

小さな iPhone アプリケーションを作成しました。UITableView を配置し、いくつかの UIView をセル内に配置しました。セル内のビューを水平に移動する機能を追加しました。UIViewで指を垂直に動かすと、UITableView全体を垂直に移動するロジックを追加したいと思います。それが私のコードです:

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

    if([recognizer state] == UIGestureRecognizerStateBegan)
    {
        CGPoint location = [recognizer locationInView:[self superview]];
        prevPos = location;
        startPosition = self.frame.origin.x;

    }
    else if([recognizer state] == UIGestureRecognizerStateChanged)
    {
        CGPoint location = [recognizer locationInView:[self superview]];
        float delX =  location.x - prevPos.x;
        float delY =  location.y - prevPos.y;
        if(delX > 0 && delX * delX > delY * delY)
        {
            CGPoint np = CGPointMake(self.frame.origin.x+delX, self.frame.origin.y);
            CGRect fr = self.frame;
            fr.origin = np;
            self.frame = fr;
            prevPos = location;
        }
        else if(delX * delX < delY * delY)
        {

        }
    }
    else if([recognizer state] == UIGestureRecognizerStateEnded ||
            [recognizer state] == UIGestureRecognizerStateFailed ||
            [recognizer state] == UIGestureRecognizerStateCancelled)
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.5];

        CGRect rect = self.frame;
        rect.origin.x = startPosition;
        self.frame = rect;
        startPosition = 0;
        [UIView commitAnimations];
    }
}

この状態でどのコードを入力すればよいですか: else if(delX * delX < delY * delY)?

ありがとう!

4

1 に答える 1

1

TableView をスクロールする場合は、TableView の contentOffset プロパティを変更する必要があります。

setContentOffset:animated:ドキュメントを見てください

于 2012-05-10T10:47:28.957 に答える