2013-01-21 53 views
0

我正在探索在iOS設備上處理觸摸事件的方式。我參考了這本書:iOS Open Application Development。在此基礎上,我重寫了mouseDown,mouseUp方法,並簡單地在一個警告框中顯示座標。但是,重寫的方法永遠不會被調用。以下是從UIView派生的newView類的代碼:在iOS設備上處理觸摸事件

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

更好的起點就在這裏: 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 
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子類的事件。

相關問題