【发布时间】:2013-07-04 09:27:04
【问题描述】:
我正在尝试设计一个视图,其中包含要订购并放入数组的项目列表。这些项目是动态生成的,因此冷的数量会超出屏幕底部。
出于这个原因,我的第一个视图是UIScrollview,它占据了整个设备屏幕
嵌套在这个标签下,我有一个标签,解释列表的用途以及如何与之交互,然后是 UITableView 与来自 http://b2cloud.com.au/how-to-guides/reordering-a-uitableviewcell-from-any-touch-point 的委托方法的拖放
我面临的问题是,虽然脚本在有 1 或 2 行时运行良好,但当 UIscrollview 的内容大小大于屏幕时,它似乎优先于拖放导致不可预测的行为.
有什么方法可以让点击表格优先只编辑单元格并允许用户通过在视图上的其他地方进行交互来滚动?
谢谢
更新
根据下面的评论,我设法得到:
- (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];
}
}
现在,当滚动视图不足以开始滚动时,NSLogs 消息正常 但是,当滚动视图较长时,它仅在滚动视图尚未开始滚动时才识别手势
更新
我现在让控制台可以 100% 地识别表格中的触摸并禁用滚动。然而,禁用滚动也会停止拖放功能。有谁知道为什么?
附加代码:
tapGesture.delegate = self;
#pragma mark UIGestureRecognizerDelegate
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
【问题讨论】:
-
我读过一些类似的文章,并且一致的是,每当与 tableview 交互时,我都需要取消或禁用滚动行为。我曾尝试设置 canCancelContentTouches = No 但主要问题是表格视图在滚动开始之前没有注册任何交互...我将尝试其他一些方法/侦听器并报告:)
标签: ios objective-c uiscrollview