我在UITableView上添加了一个UITableView作为子视图。 我在UITableView(子视图)上的“传递”触摸到UIViewController的视图(在这里我的touchesBegan:方法按预期工作)令人不安。
我尝试过:
也:在tableView上禁用userInteraction可以,但是,当然,我仍然想维护cellDidSelectRow ..功能。
我在ViewController中的代码实现:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesBegan popup");
if (!self.draggable) {
//[super touchesBegan:touches withEvent:event];
return;
}
UITouch *touch = [touches anyObject];
if (!_moving) {
//(touch.view == self || touch.view.superview == self) &&
_moving = YES;
_movingStartY = [touch locationInView:self.view].y;
NSLog(@"moving popup");
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.draggable) {
//[super touchesMoved:touches withEvent:event];
return;
}
if (_moving) {
NSLog(@"touchesMoved popup");
UITouch *touch = [touches anyObject];
float offset = [touch locationInView:self.view].y - _movingStartY;
if ([self.touchEventDelegate respondsToSelector:@selector(popupNavigationBar:touchDidMoveWithOffset:)]) {
[self.touchEventDelegate popupNavigationBar:self touchDidMoveWithOffset:offset];
}
}
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.draggable) {
//[super touchesCancelled:touches withEvent:event];
return;
}
if (_moving) {
UITouch *touch = [touches anyObject];
float offset = [touch locationInView:self.view].y - _movingStartY;
[self movingDidEndWithOffset:offset];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.draggable) {
//[self touchesEnded:touches withEvent:event];
return;
}
if (_moving) {
UITouch *touch = [touches anyObject];
float offset = [touch locationInView:self.view].y - _movingStartY;
[self movingDidEndWithOffset:offset];
}
}
- (void)movingDidEndWithOffset:(float)offset
{
_moving = NO;
if ([self.touchEventDelegate respondsToSelector:@selector(popupNavigationBar:touchDidEndWithOffset:)]) {
[self.touchEventDelegate popupNavigationBar:self touchDidEndWithOffset:offset];
}
}
我该怎么做?