gpt4 book ai didi

objective-c - 如何垂直移动 UITableView

转载 作者:行者123 更新时间:2023-11-29 13:36:32 25 4
gpt4 key购买 nike

我已经创建了小型 iPhone 应用程序。我把 UITableView 和一些 UIView 放在单元格中。我添加了在单元格中水平移动 View 的功能。现在,如果我在 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)

谢谢!

最佳答案

如果你想滚动一个 TableView,你需要改变 TableView 的 contentOffset 属性。

查看setContentOffset:animated:文档

关于objective-c - 如何垂直移动 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10450155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com