2012-09-14 70 views
2

我試圖在我的代碼中設置點按手勢,並在嘗試確定座標時發生崩潰。任何幫助,將不勝感激。嘗試設置手勢識別時發生崩潰

2012-09-14 17:25:49.149 valhalla[16469:707] tap detected 
2012-09-14 17:25:49.159 valhalla[16469:707] -[UITapGestureRecognizer translationInView:]: unrecognized selector sent to instance 0x37bf10 
2012-09-14 17:25:49.165 valhalla[16469:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITapGestureRecognizer translationInView:]: unrecognized selector sent to instance 0x37bf10' 
*** First throw call stack: 
(0x3104c88f 0x3611d259 0x3104fa9b 0x3104e915 0x3104f788 0x7a4a1 0x31870637 0x31800d65 0x31a31479 0x3177cf55 0x3177baa3 0x317887e9 0x31788627 0x317881f5 0x3176e695 0x3176df3b 0x313e222b 0x31020523 0x310204c5 0x3101f313 0x30fa24a5 0x30fa236d 0x313e1439 0x3179ccd5 0x75307 0x752c8) 




#import "GLViewController.h" 
#import "GLView.h" 

@implementation GLViewController 

- (void)loadView { 

    CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame]; 

    GLView *glView = [[[GLView alloc] initWithFrame:applicationFrame] autorelease]; 
    self.view = glView; 
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] 
             initWithTarget:self action:@selector(handleSingleTap:)]; 
    singleTap.numberOfTapsRequired = 1; 
    [self.view addGestureRecognizer:singleTap]; 
    [singleTap release]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // We can run in landscape mode 
    return (UIInterfaceOrientationIsLandscape(interfaceOrientation)); 
} 

/*- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 

    //[self.view becomeFirstResponder]; 
    //[self.view setReturnKeyType:UIReturnKeyDone]; 
}*/ 
- (void)didReceiveMemoryWarning 
{ 
    // default behavior is to release the view if it doesn't have a superview. 

    // remember to clean up anything outside of this view's scope, such as 
    // data cached in the class instance and other global data. 
    [super didReceiveMemoryWarning]; 
} 

- (void) handleSingleTap: (UIPanGestureRecognizer *) uigr 
{ 
    NSLog(@"tap detected"); 
    CGPoint translation = [uigr translationInView:self.view]; 
    CGPoint finalPosition = self.view.center; 
    finalPosition.x += translation.x; 
    finalPosition.y += translation.y; 

} 

@end 

回答

4

你聲明UITapGestureRecognizer但你的方法被轉換成一UIPanGestureRecognizer

- (void) handleSingleTap: (UIPanGestureRecognizer *) uigr 

UITapGestureRecognizer沒有聲明translationInView。這就是爲什麼你的應用程序崩潰。

1

您想使用locationInView:而不是translationInView: