4
雖然我知道如何在基於視圖的應用程序中使用手勢識別器,但是當我在基於OpenGLSE的應用程序中應用相同的想法時:例如 ,我添加了TapGestureRecognizer,崩潰。 那麼任何人都可以在基於OpenGLES的應用程序中向我展示UITapGestureRecognizer的標準用法嗎?如何在iPhone的OpenGLES應用程序中使用手勢識別器?
最好的祝願。
雖然我知道如何在基於視圖的應用程序中使用手勢識別器,但是當我在基於OpenGLSE的應用程序中應用相同的想法時:例如 ,我添加了TapGestureRecognizer,崩潰。 那麼任何人都可以在基於OpenGLES的應用程序中向我展示UITapGestureRecognizer的標準用法嗎?如何在iPhone的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");
}
我已經沒有這種直接經驗,但你嘗試過將它添加到父視圖(如而不是窗戶)?不知道爲什麼,但它可能需要某些未在CAEAGLLayer類中實現的圖層功能。 – jhabbott 2010-10-03 17:42:34
這非常奇怪,因爲我有OpenGL ES託管視圖響應正常的觸摸事件而沒有發生意外。爲什麼手勢識別器的行爲會有所不同? – 2010-10-04 01:00:58
我使用基本的UIViews和EAGLViews的輕拍手勢識別器,它們的工作原理完全相同。其他地方可能有問題。你的故障記錄是什麼意思? – 2010-10-05 01:06:47