我有一个UITableViewCell
子类,我UIView
在它的contentView
属性中添加了一个。为了启用拖动该子视图,我实现了UIResponder
适当的方法:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentLocation = [touch locationInView:self.superview];
if (currentLocation.x >= self.rootFrame.origin.x) {
return;
}
CGRect frame = self.frame;
frame.origin.x = currentLocation.x;
self.frame = frame;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
self.frame = self.rootFrame; // rootFrame is a copy of the initial frame
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesEnded:touches withEvent:event];
}
子视图可以毫无问题地拖动,但单元格也被选中,因此-tableView:didSelectRowAtIndexPath:
被调用。
如何防止在拖动子视图时单元格被选中?