4

ビューベースのアプリケーションでジェスチャレコグナイザーを使用する方法は知っていますが、OpenGLSEベースのアプリケーションで同じアイデアを適用すると、たとえば、TapGestureRecognizerを追加し、EAGLViewをタップするとクラッシュします。では、OpenGLESベースのアプリケーションでのUITapGestureRecognizerの標準的な使用法を誰かに教えてもらえますか?

幸運をお祈りしています。

4

1 に答える 1

4

ここに、ジェスチャーをサポートする私のopenglesゲームの1つからのサンプルコードがあります。(クラッシュせず、役立つことを願っています)

- (void)viewDidLoad {
    [super viewDidLoad];

    CGRect  rect = [[UIScreen mainScreen] bounds];
    rect.size.height = 320;
    rect.size.width = 480;
    rect.origin.x = 0;
    rect.origin.y = 0;

    glView = [[EAGLView alloc] initWithFrame:rect pixelFormat:GL_RGB565_OES depthFormat:GL_DEPTH_COMPONENT16_OES preserveBackbuffer:NO];
    [self.view addSubview: glView];

    [glView addSubview: minimapView];

    if(!shell->InitApplication())
        printf("InitApplication error\n");

    [NSTimer scheduledTimerWithTimeInterval:(1.0 / kFPS) target:self selector:@selector(update) userInfo:nil repeats:YES];

    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(Panned:)];
    [glView addGestureRecognizer:[pan autorelease]];    

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Tapped:)];
    [glView addGestureRecognizer:[tap autorelease]];    

    UITapGestureRecognizer *dbltap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(DoubleTapped:)];
    [dbltap setNumberOfTapsRequired:2];
    [glView addGestureRecognizer:[dbltap autorelease]];

    UILongPressGestureRecognizer *longpress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(LongPressed:)];
    [glView addGestureRecognizer:[longpress autorelease]];      
}

そしてセレクター機能

- (void) LongPressed:(UILongPressGestureRecognizer*)sender{
    NSLog(@"Long Pressed");
}
于 2011-01-26T19:31:39.980 に答える