【问题标题】:How to use gesture recognizer in an OpenGLES application of iPhone?如何在 iPhone 的 OpenGLES 应用程序中使用手势识别器?
【发布时间】:2010-10-03 14:03:05
【问题描述】:

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

祝你好运。

【问题讨论】:

  • 我对此没有直接经验,但您是否尝试将其添加到父视图(例如窗口)中?不知道为什么,但它可能需要一些在 CAEAGLLayer 类中未实现的层功能。
  • 这很奇怪,因为我已经让 OpenGL ES 托管视图响应正常的触摸事件而没有发生任何事件。为什么手势识别器的行为会有所不同?
  • 我已经为基本的 UIViews 和 EAGLViews 使用了轻击手势识别器,它们的工作原理完全相同。你可能在其他地方有问题。你的崩溃日志是怎么说的?

标签: iphone opengl-es ios4 eaglview


【解决方案1】:

这里有一些示例代码,来自我的一款支持手势的 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");
}

【讨论】:

    猜你喜欢
    • 2012-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-07
    • 1970-01-01
    相关资源
    最近更新 更多