触摸方法不适用于发布版本

发布于 2024-07-17 08:11:17 字数 756 浏览 3 评论 0原文

我遇到一个奇怪的问题,我为 iPhone 构建的自定义控件在调试模式下构建时可以完美工作,但在发布模式下构建时只能部分工作。

主包装视图是 UIView 的子类,它包含一行作为子视图添加的“按钮”。 自定义按钮类扩展了 UIImageView 并使用以下签名覆盖触摸方法:

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

构建调试代码时,所有 4 个函数都会在您期望的时间调用,而在发布版本中,不会发生任何事情。 我已经登录了它们中的每一个,但没有收到任何日志消息(其他日志记录正在工作)。

另一个有趣的事情是,我在包装视图类中重写了 TouchBegan/Moved/Ended 方法,并且它们工作正常。 我尝试在包装类中注释掉这些方法,看看它是否对按钮有影响,但没有。

我还尝试将 UIImageView 类更改为 UIButton 的子类,但在那里遇到了相同的问题,包括 touchUpInside 等任何事件。 它们在调试时工作,但在发布时不工作。

我尝试研究这个问题以及一般事件处理,但一无所获。 有什么想法下一步该去哪里吗?

I'm having a strange issue where a custom control I've built for the iPhone works perfectly when building in debug mode but only works partially when built in release mode.

The main wrapper view is a subclass of UIView and it contains a row of "buttons" that are added as subviews. The custom button class extends UIImageView and is overriding the touch methods with the following signatures:

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

When building debug code, all 4 of these functions are called at the times you would expect, with a release build, nothing happens. I have logging in each of them and I'm not getting any log messages (other logging is working).

Another interesting thing, I have the touchesBegan/Moved/Ended methods overridden in the wrapper view class and they are working fine. I've tried commenting out those methods in the wrapper class to see if it had an effect on the buttons but it did not.

I've also tried changing the UIImageView class to be a subclass of UIButton instead but am having the same issue there, including any events like touchUpInside. They work in debug, but not release.

I've tried researching this issue as well as general event handling and have come up empty handed. Any ideas where to look next?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你与清晨阳光 2024-07-24 08:11:17

我终于弄清楚了问题 - “按钮”项目的包装器的高度为 0。在调试模式下,应用程序发现按钮被触摸,即使它们不在其父视图的点击区域内( ClipsToBounds 默认为 NO,因此按钮项目仍然完全可见),在发布模式下,则没有那么多。

希望这可以帮助一些人节省我必须经历的头痛和调试时间:)我也将其发布到苹果的一个错误中,希望有一天它能得到修复。

I finally figured out the issue - the wrapper for the "button" items had a height of 0. In debug mode, the app figured out that the buttons were being touched even though they weren't inside the hit area of their parent view (clipsToBounds was defaulted to NO so the button items were still perfectly visible), in release mode, not so much.

Hopefully this can help save some people the head scratching and debugging time that I had to go through :) I've also posted this to a bug at Apple so hopefully it will be fixed someday.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文