我有一个 UITableView ,它有一个 UIImageView ,通过单击按钮(上/下)一次遍历一行。我现在想做的是只允许用户向上或向下拖动 UIImageView 表(即没有横向移动)。如果 UIImageView 的大部分位于特定单元格上,那么当用户松开手指时,我希望 UIImageView 链接到该行。这是 UITableView 的图像,带有 UIImageView:
滚动条是需要移动或向下移动的 UIImageView。我意识到我应该实现以下方法:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// We only support single touches, so anyObject retrieves just that touch from touches.
UITouch *touch = [touches anyObject];
if ([touch view] != _imageView) {
return;
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ([touch view] == _imageView) {
return;
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
//here is where I guess I need to determine which row contains majority of the scrollbar. This would only measure the y coordinate value, and not the x, since it will only be moving up or down.
return;
}
}
但是,我不确定如何实现此功能。我试图在网上找到类似的示例,并且查看了 Apple 的 MoveMe 示例代码,但我仍然卡住了。另请注意,我的滚动条与表格中的行大小不完全相同,而是更长一些,但高度相同。
提前感谢所有回复的人