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 回答