gpt4 book ai didi

ios - 在 UIScrollView 中拖放

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:42:02 25 4
gpt4 key购买 nike

我正在尝试设计一个 View ,其中包含要订购并放入数组中的项目列表。这些项目是动态生成的,因此是一个超出屏幕底部的数量。

出于这个原因,我的第一个 View 是 UIScrollview,它占据了整个设备屏幕嵌套在这个下面我有一个标签,解释了列表的用途以及如何与之交互,然后是一个 UITableView,带有来自 http://b2cloud.com.au/how-to-guides/reordering-a-uitableviewcell-from-any-touch-point 的委托(delegate)方法的拖放功能。

我面临的问题是,虽然脚本在有 1 行或两行时效果很好,但当 UIscrollview 的内容大小大于屏幕时,它似乎优先于拖动 &下降导致不可预测的行为。

有什么方法可以使表格上的点击优先于仅编辑单元格并允许用户通过在 View 的其他地方进行交互来滚动?

谢谢

更新

根据下面的评论我设法得到:

- (void)viewDidLoad
{
[super viewDidLoad];
//
//
//

UIPanGestureRecognizer *tapGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(wasPanned:)];
[self.view addGestureRecognizer:tapGesture];
}
-(void)wasPanned:(UIPanGestureRecognizer *)gesture
{
CGPoint point = [gesture locationInView:scrollView];
UIView *isTable = [scrollView hitTest:point withEvent:nil];
if (gesture.state == UIGestureRecognizerStateBegan)
{
if([[[isTable class] description] isEqualToString:@"UITableViewCellReorderControl"])
{
NSLog(@"Dragged from within table");
[scrollView setScrollEnabled: NO];

}
else
{
[scrollView setScrollEnabled:YES];
}
}
else{
[scrollView setScrollEnabled:YES];
}
}

现在,当 ScrollView 的长度不足以开始滚动时,NSLogs 消息正常然而,当 ScrollView 更长时,如果 ScrollView 还没有首先开始滚动,它只会识别手势

更新

我现在让控制台 100% 地识别表格中的触摸并禁用滚动。但是,禁用滚动也会停止拖放功能。有谁知道为什么吗?

额外代码:

tapGesture.delegate = self;

#pragma mark UIGestureRecognizerDelegate
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}

最佳答案

所以我最终(但不完美)的解决方案是这样做:

.h

<UIGestureRecognizerDelegate>

.m (viewDidLoad)

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(wasTapped:)];
[self.view addGestureRecognizer:tapGesture];
tapGesture.delegate = self;

.m

-(void)wasTapped:(UIPanGestureRecognizer *)gesture
{
CGPoint point = [gesture locationInView:scrollView];
UIView *isTable = [scrollView hitTest:point withEvent:nil];
if (gesture.state == UIGestureRecognizerStateBegan)
{
if([[[isTable class] description] isEqualToString:@"UITableViewCellReorderControl"])
{
NSLog(@"Dragged from within table");
[scrollView setScrollEnabled: NO];

}
else
{
[scrollView setScrollEnabled:YES];
}
}
else{
[scrollView setScrollEnabled:YES];
}
}

点击手势比平移手势效果更好,因为平移手势似乎将按住、拖动、停止、拖动识别为两种不同的手势。该功能现在可以正常工作,但如果您在移动单元格的动画开始之前移动手指,它就会滚动。您还必须等待 View (我可以称之为过度滚动吗?)动画完全停止并且滚动条消失,然后它才会抓取单元格。

如果有人可以改进它,我将不胜感激:)

关于ios - 在 UIScrollView 中拖放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17466671/

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