iOS多点触摸不工作
我正在进行常规OpenGL/EAGL设置:iOS多点触摸不工作,ios,objective-c,multi-touch,uitouch,eaglview,Ios,Objective C,Multi Touch,Uitouch,Eaglview,我正在进行常规OpenGL/EAGL设置: @interface EAGLView : UIView { @public EAGLContext* context; } @property (nonatomic, retain) EAGLContext* context; @end @implementation EAGLView @synthesize context; + (Class)layerClass { return [CAEAGLLayer class]; } @
@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];
}
这一切编译得很好,但我从来没有收到超过一个UITouch。我不是说一次触球就开始了,但指数永远不会超过0。我还为它第二次进入该功能设置了一个断点,并且将两个手指放在上面不会触发它。如果您想检测多个触摸(和/或区分一个手指、两个手指等触摸),请尝试使用UIPangestureRecognitor。设置时,可以指定最小和最大触摸次数。然后将其附加到要检测触摸的视图。当您收到来自它的事件时,您可以询问它收到了多少触摸,并相应地进行分支 以下是苹果的文档:
如果您这样做,您可能根本不需要使用touchsbegind/Moved/end方法,并且根据您如何设置手势识别器,touchsbegind/Moved/end可能永远不会被调用 使用
[事件所有触摸]
代替触摸
<代码>触摸仅表示已“更改”的触摸。从苹果文档:
如果您对自上一次接触以来没有改变的接触感兴趣
相位或处于与中的触摸不同的相位
传入集合后,可以在事件对象中找到这些集合。图3-2
描述包含触摸对象的事件对象。得到全部
这些触摸对象调用事件对象上的AllTouchs方法
似乎我所缺少的就是:
sViewController.view = sViewController.glView;
我真的必须使用touchsbegind/Moved/end,因为我在较低级别(游戏引擎)上处理手势/触摸。它目前在其他平台上运行。您是否也在TouchsMoved中检查多点触摸?是的
touchsmoved
似乎也不会显示多个触摸。如果它这样做了,我的代码也会崩溃,因为它希望touchesbeated
首先使用特定的UITouch触发。不幸的是,这并不能解释为什么touchesbeated
没有为我的食指触发。似乎如果视图没有与视图控制器直接关联,多点触摸就不能正常工作。
sViewController.view = sViewController.glView;