如何调用superview的touchesBegan:(NSSet *)触及withEvent:(UIEvent *)事件方法?

时间:2014-05-07 17:49:27

标签: ios uiview uiviewcontroller uitouch uiresponder

我创建了一个UIView子视图,我在故事板中添加到我的UIViewController,我想回应子视图上的点击并调用superview的以下方法的实现。调用正常,但它不会将正确的touch.tapcount作为参数传递给superview的实现。

以下是子视图中的方法:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    CGRect rect = [[UIScreen mainScreen] bounds];
    UITouch *touch = [[event touchesForView:self]anyObject];
    CGPoint location = [touch locationInView:self];

    if(touch.tapCount == 2){

        [self.superview touchesBegan:touches withEvent:event];

    }
}

以下是superview中的方法,if块未执行:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    CGRect rect = [[UIScreen mainScreen] bounds];
    UITouch *touch = [[event touchesForView:self]anyObject];
    CGPoint location = [touch locationInView:self];

    if(touch.tapCount == 2){

      //Code is not executed here
    }
}

解决方案

在superview中更改此语句:

UITouch *touch = [[event touchesForView:self]anyObject];

到此:

UITouch *touch = [[event touchesForView:[self.view.subviews objectAtIndex:1]] anyObject];

0 个答案:

没有答案