iphone - 在 iOS 设备上处理触摸事件

标签 iphone ios ios4 gesture-recognition iphone-privateapi

我正在探索在 iOS 设备上处理触摸事件的方式。我提到了这本书:iOS Open Application Development .为此,我重写了 mouseDown、mouseUp 方法,并简单地在警告框中显示坐标。但是,重写的方法永远不会被调用。以下是派生自 UIView 的 newView 类的代码:

-(void) _mouseDown: (GSEventRef) event{
CGPoint point =GSEventGetLocationInWindow(event);
UIAlertView* alert;
NSString* alertString =[NSString stringWithFormat: @"%f %f", point.x, point.y];
alert = [[UIALertView alloc] initWithTitle:@"Success" message:alertString delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}

-(BOOL) canHandleGestures{
return YES;
}

有没有我遗漏的部分?另外,有没有其他方法可以获取有关触摸事件的信息并进行处理?

最佳答案

更好的起点是: https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/multitouch_background/multitouch_background.html

这些是您可以在 UIView 子类中覆盖的方法:

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

关于iphone - 在 iOS 设备上处理触摸事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14436064/

相关文章:

ios - 用 cocos2d 3 在圆圈中蒙版 Sprite

javascript - 在 iOS 的 javascript 中禁用长按振动

ios - IPA 文件困惑。如何确定我的 .ipa 文件是否可以在另一台 iPhone 上运行?

iphone - 拉伸(stretch) UIImage 同时保留角点

iphone - 将导入的数据保存到核心数据 - 无法读回

iphone - UIAlertView 每次调用都会弹出三次,而不是一次

iphone - 将音频输出到配对的蓝牙设备?

ios - 在 UIScrollView 中绘制图形

iphone - iOS 原始视频捕获 - 从哪里开始?

iphone - 检查 objective-c 枚举是否存在