我有一个包含 UITableView 的 viewController。这个viewController实现了UITableViewDelegate和UITableViewDataSource,我也在尝试实现以下方法:
touchesBegin touchesMoved touchesEnded
但是,这些方法没有被调用。我试图调用这些方法以响应用户触摸 UITableView 内的 UIImageView,但这样做只会调用此方法:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.view bringSubviewToFront:_imageView];
[UIView animateWithDuration:.3 animations:^{
CGRect rect = [self.view convertRect:[tableView rectForRowAtIndexPath:indexPath] fromView:tableView];
CGFloat floatx = _imageView.frame.origin.x - rect.origin.x;
_imageView.frame = CGRectMake(rect.origin.x + floatx, rect.origin.y, _imageView.frame.size.width, _imageView.frame.size.height);
}];
NSLog(@"Table row %d has been tapped", indexPath.row);
}
我希望是继续调用这个方法,但也调用:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ([touch view] == _imageView) {
//need to make sure user can only move the UIImageView up or down
CGPoint location = [touch locationInView:_imageView];
//ensure UIImageView does not move outside UIITableView
CGPoint pt = [[touches anyObject] locationInView:_imageView];
CGRect frame = [_imageView frame];
//Only want to move the UIImageView up or down, not sideways at all
frame.origin.y += pt.y - _startLocation.y;
[_imageView setFrame: frame];
_imageView.center = location;
return;
}
}
当用户在 UITableView 内拖动 UIImageView 时。
谁能看到我做错了什么?
提前感谢所有回复的人