4

虽然我知道如何在基于视图的应用程序中使用手势识别器,但是当我在基于 OpenGLSE 的应用程序中应用相同的想法时:例如,我添加了一个 TapGestureRecognizer,当我点击 EAGLView 时,它会崩溃。那么任何人都可以在基于 OpenGLES 的应用程序中向我展示 UITapGestureRecognizer 的标准用法吗?

最好的祝愿。

4

1 回答 1

4

这是我的一款支持手势的 opengles 游戏的示例代码。(不会崩溃,希望对您有所帮助)

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