开始在UIViewController上接收touches-目标C

时间:2019-03-16 14:42:32

标签: ios objective-c uitableview cocoa-touch

我在UITableView上添加了一个UITableView作为子视图。 我在UITableView(子视图)上的“传递”触摸到UIViewController的视图(在这里我的touchesBegan:方法按预期工作)令人不安。

我尝试过:

  • 将我的UITableView子类化,并将touchesBegan:从那里传递给超级视图
  • pointInside:在超级视图中
  • hitTest:在子类tableView中

也:在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];
    }
}

我该怎么做?

0 个答案:

没有答案