虽然我知道如何使用手势识别的基于视图的应用程序,但是当我使用同样的方法在基于OpenGLSE的应用程序: 例如, 我添加了一个TapGestureRecognizer,当我在EAGLView挖掘,它崩溃。 因此,谁能告诉我UITapGestureRecognizer的标准用法在基于OpenGLES的应用程序?

祝福。

有帮助吗?

解决方案

下面从我的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");
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top