我正在探索在 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;
}
有没有我遗漏的部分?另外,有没有其他方法可以获取有关触摸事件的信息并进行处理?
最佳答案
这些是您可以在 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/