我正在进行常规的 OpenGL / EAGL 设置:
@interface EAGLView : UIView {
@public
EAGLContext* context;
}
@property (nonatomic, retain) EAGLContext* context;
@end
@implementation EAGLView
@synthesize context;
+ (Class)layerClass {
return [CAEAGLLayer class];
}
@end
@interface EAGLViewController : UIViewController {
@public
EAGLView* glView;
}
@property(nonatomic, retain) EAGLView* glView;
@end
@implementation EAGLViewController
@synthesize glView;
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
for (UITouch* touch in touches) {
CGPoint location = [touch locationInView:glView];
int index;
for (index = 0; index < gCONST_CURSOR_COUNT; ++index) {
if (sCursor[index] == NULL) {
sCursor[index] = touch;
break;
}
}
}
[super touchesBegan:touches withEvent:event];
}
该实现还包括相应的 touchesEnded/Canceled/Moved。该代码完全有效并且可以很好地跟踪。
我还确保为所有内容提供正确的值:
sViewController = [EAGLViewController alloc];
CGRect rect = [[UIScreen mainScreen] applicationFrame];
sViewController.glView = [[EAGLView alloc] initWithFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)];
Assert(sViewController.glView);
sViewController.glView.userInteractionEnabled = YES;
sViewController.glView.multipleTouchEnabled = YES;
sViewController.glView.exclusiveTouch = YES;
这一切都编译得很好,但我从来没有收到超过一个 UITouch。我的意思不是在一次 touchesBegan 中,但索引永远不会超过 0。我还为它第二次进入该函数设置了一个断点,并且将两根手指放在上面不会触发它。