gpt4 book ai didi

ios - 屏幕左/左下角的 UINavigationController 和触摸事件

转载 作者:行者123 更新时间:2023-11-29 10:52:32 24 4
gpt4 key购买 nike

我正在尝试使用 UIControlEventTouchDown 事件为简单的 UIButton 调用操作,它放置在 UIViewController 的左下角(用UINavigationController).

我创建了 Storyboard来使用按钮推送 View Controller 。

storyboard

并为按钮添加了跟踪触摸事件的 Action 。

- (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 不会像正常行为那样在触地时被调用。但是只有在 touch up 之后才会被调用。

touchareas

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

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

最佳答案

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

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

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

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

关于ios - 屏幕左/左下角的 UINavigationController 和触摸事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19867462/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com