【问题标题】:UINavigationController and Touch Events in Left / Left-Bottom Corner of ScreenUINavigationController 和屏幕左/左下角的触摸事件
【发布时间】:2013-11-20 23:01:04
【问题描述】:

我正在尝试使用UIControlEventTouchDown 事件来调用简单的UIButton 事件,该事件位于UIViewController 的左下角(使用UINavigationController 推送)。

我创建了故事板来推动带有按钮的视图控制器。

并为按钮添加操作以跟踪触摸事件。

- (IBAction)touchUpInside:(id)sender {
    NSLog(@"touchUpInside");
}

- (IBAction)touchDown:(id)sender {
    NSLog(@"touchDown");
}

并且还添加了 touchesBegan 来追踪是否被调用。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self touchesBegan:touches withEvent:event];
    NSLog(@"touchesBegan");
}

现在,通过这样的设置,我的行为很奇怪。左侧(宽度 = 13)和左下(宽度 = 50,高度 = 50)有一些触摸区域对触摸的响应不同。如果您将触及这些区域 -touchesBegan 不会像正常行为那样在着陆时被调用。但它只会在修饰后调用。

我相信 UINavigationControler 中使用了左侧区域,用于推送 UIViewController 的交互式弹出。所以这里有两个问题。

  1. 左下角的区域负责哪些功能?
  2. 如何以及在何处更改行为以将触摸事件传递给 UIButton(例如,如果我希望 UIButton 在我按下“红色”区域时响应长触摸事件)?

【问题讨论】:

    标签: ios objective-c cocoa-touch events uinavigationcontroller


    【解决方案1】:

    我遇到了同样的问题,我通过禁用 iOS 7 中引入的“滑动返回”(技术上称为 UIKit 中的“交互式弹出手势”)功能解决了这个问题。

    禁用交互式弹出手势的示例代码:

    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
    

    我相信这是由于交互式弹出手势识别器消耗/延迟屏幕左边缘附近的触摸事件(因为从左边缘开始滑动返回),从而导致触摸事件无法传递到位于视图左边缘附近的控件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-02
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 2020-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多