我想在所有视图中捕捉触摸事件。所以它应该处理appdelegate
。如何在应用程序的每个视图中捕捉触摸事件?
我提到
iPhone: Detecting user inactivity/idle time since last screen touch
,但没有成功
希望我会在正确的方向得到
感谢
我想在所有视图中捕捉触摸事件。所以它应该处理appdelegate
。如何在应用程序的每个视图中捕捉触摸事件?
我提到
iPhone: Detecting user inactivity/idle time since last screen touch
,但没有成功
希望我会在正确的方向得到
感谢
只实现
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
//your logic
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
//your logic
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//your logic
}
在你的代码中..我认为你可以想出其余的想法。
应用程序委托不是响应者。我将继承UIWindow,并重写它的事件处理方法,因为窗口首次获取所有触摸事件。
与futureelilte7所说的相反,您的应用程序委托(在创建项目时生成)实际上是UIResponder的子类,并响应选择器touchesBegan:withEvent:
和其他类似选择器。
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
// your code here
}
这应该保留默认触摸行为,并给你一个机会做自己的自定义功能。
没有需要继承的UIWindow,简单的直通手势样本这里的代码,捕获所有接触所有的观点:
谢谢...但问题是如何实现它在应用程序委托class.I知道它可以在视图控制器中完成。但是,在所有视图控制器中编写代码将非常繁琐 – illuminatus 2011-02-10 03:42:00
应用程序委托不是UIResponder子类。屏幕上没有代表的可视化表示,所以您的建议是没有意义的。只要检测窗口的触摸,但你必须自己处理所有的触摸。 – futureelite7 2011-02-10 06:42:03