- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试调试游戏中一些与 TouchBegan/Moved/Ended 相关的减速问题;我认为我的一些触摸响应器没有正确卸载,因此随着游戏在越来越多的触摸响应器上运行,触摸响应器会变得越来越不响应,因为它们必须通过越来越大的响应器链。
是否有某种方法可以查看/检索 UITouch 在链中移动时所采取的路径?或者只是某种方式来检索所有事件响应者的列表?
谢谢,-S
最佳答案
您可以劫持 UIResponder
上所需的方法来添加日志记录,然后调用原始方法。这是一个例子:
#import <objc/runtime.h>
@interface UIResponder (MYHijack)
+ (void)hijack;
@end
@implementation UIResponder (MYHijack)
+ (void)hijackSelector:(SEL)originalSelector withSelector:(SEL)newSelector
{
Class class = [UIResponder class];
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method categoryMethod = class_getInstanceMethod(class, newSelector);
method_exchangeImplementations(originalMethod, categoryMethod);
}
+ (void)hijack
{
[self hijackSelector:@selector(touchesBegan:withEvent:) withSelector:@selector(MYHijack_touchesBegan:withEvent:)];
}
- (void)MYHijack_touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touches!");
[self MYHijack_touchesBegan:touches withEvent:event]; // Calls the original version of this method
}
@end
然后在您的应用程序中的某个位置(我有时将其放在 main()
本身中),只需调用 [UIResponder hijack]
即可。只要 UIResponder
子类在某个时刻调用 super
,您的代码就会被注入(inject)。
method_exchangeImplementations()
是一件美丽的事情。当然要小心;它非常适合调试,但如果不加区别地使用会非常困惑。
关于iphone - 有没有办法检索每个处理过 UITouch 的响应者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1929740/
我正在尝试制作一个函数,以便当鸟接触其中一根管道时应该发生一些事情(我稍后会写下来)但是我马上就遇到了一个错误,我不知道如何修复它。 出现错误的是“UITouch”部分我已经尝试将多个不同的代码放在那
我想让每个UITouch实例记录一次点击。换句话说,无论多次点击发生得有多近,我都希望它们各自创建一个唯一的触摸实例。这可能吗? 谢谢, 道格 最佳答案 这个问题的背后是我需要为每个点击将唯一地址与每
我在写作时使用多点触控,所以基本上我所做的是,我在手部支持下写作,因为通常情况下,它是用户书写的方式,我点击了此链接 How to ignore certain UITouch Points in m
我有以下问题: 如果我用一根手指(即中指)点击触摸屏并靠近手指向上的那一刻,我用第二根手指(即食指)点击靠近另一根手指所在的区域,而不是获得向下事件,我的第一根手指移动到 第二根手指的向下位置。重现有
我想设置一个全局 UITouch 处理程序来调试正在通过系统的所有 UITouch 事件以及哪个 View 是目标等。我该如何实现? 最佳答案 创建一个 UIApplication 的子类来覆盖 se
我有一个大图像(1024, 1496)作为我的图层的背景图像。所以我开始显示图像的按钮。在应用时,我显示了图像的顶部和一些 CCSprites。 id move = [CCMoveBy actionW
您将如何设置模拟 UITouches 的回归测试? 我正在开发一款 iOS 游戏,希望对核心功能进行一些回归测试。我需要自动触发对 touchesBegan:(NSSet *)touches with
我有一个 UIView,在他上面我有 UIButton、UITableView 和 UINavigationBar。我想要做的是,当您单击 UIButton 并拖动它时,所有 View 将仅移动到左侧
因为我非常喜欢今天关于在 Swift 中创建我自己的可以生成对象实例的类的新手教程。我希望通过在这些知识的基础上开始使用 Apple 的 Cocoa Touch API's 来变得更好。然而,在阅读
我正在构建一个允许用户在屏幕上绘图的应用程序。我想添加网络功能,以便用户 A 可以在用户 B 的屏幕上绘图。我目前的计划是构建一个系统,在其中我拥有自己的 UserOrNetworkTouch 对象,
我正在尝试检测触摸移动的速度,但并不总能得到预期的结果。 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ s
如何在 touchmoved 函数中获取手指移动的速度和方向? 我想获取手指速度和手指方向并将其应用于 UIView 类方向移动和动画速度。 我阅读了这个链接,但我无法理解答案,此外它也没有解释我如何
我希望在应用程序中从一个 subview 拖动到另一个 subview (并用一条线连接它们),因此我需要跟踪用户触摸的当前 View 。 我认为我可以通过简单地在touchesMoved方法中调用[
我正在尝试调试游戏中一些与 TouchBegan/Moved/Ended 相关的减速问题;我认为我的一些触摸响应器没有正确卸载,因此随着游戏在越来越多的触摸响应器上运行,触摸响应器会变得越来越不响应,
我有一个父 UIView 和一个子 UIView,我想让触摸从子传递到父,并由两个 View 处理。 y-------------- | parent | | x------ | |
这基本上是我试图生成图像或敌人的代码,我想删除它们,但不是通过只触摸所触摸的相同图像之一来一次性删除它们。这张图片也在移动,以防有人需要知道。 import SpriteKit import UIKi
我想从左侧和右侧创建一个节点,当我触摸它们时,小鸟会飞向左侧或右侧。 首先我创建了一个鸟节点 然后,我创建了测试节点 var groundleft = SKSpriteNode() groundlef
我无法让 UIView 通过多次触摸来响应我想要的方式。基本上某些 UITouches 在 UITouchPhaseBegan 中,但永远不会进入 UITouchPhaseEnded 或 UITouc
如何在 iOS 中使用 UITouch 检测圆形点击? - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
我正在使用CGContext画一条线。我已将线宽设置为35。现在,当调用 touches begin 时,我正在记录触摸点。但它只给出一个点,我想要触摸内的所有点,因为我的线宽是35。如何一次获得所有
我是一名优秀的程序员,十分优秀!