3

コードでタップ ジェスチャをセットアップしようとしていますが、座標を決定しようとするとクラッシュします。どんな助けでも大歓迎です。

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

2 に答える 2

5

UITapGestureRecognizer を宣言していますが、メソッドは UIPanGestureRecognizer にキャストしています

- (void) handleSingleTap: (UIPanGestureRecognizer *) uigr

UITapGestureRecognizer は translationInView を宣言しません。そのため、アプリがクラッシュしています。

于 2012-09-14T22:53:00.483 に答える
3

あなたは使いたくlocationInView:ないtranslationInView:

于 2012-09-14T22:56:36.830 に答える