0

我正在探索在 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;
}

有没有我遗漏的部分?此外,是否有另一种方法来获取有关触摸事件的信息并处理它们?

4

3 回答 3

4

更好的起点在这里: 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
于 2013-01-21T09:59:09.803 回答
3

您可以使用 :

- (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 {}

用于从 UIView 子类获取触摸事件。

于 2013-01-21T10:00:14.053 回答
1

您必须使用gesturerecognizer(如uitapgesturerecognizeruiswipegesturerecognizerUITouch events

于 2013-01-21T10:02:30.043 回答