Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 我需要帮助将UIPinchGestureRecognitor子类化,以便在挤压过程中找到触摸的位置_Objective C_Cocos2d Iphone_Box2d_Uigesturerecognizer_Uipinchgesturerecognizer - Fatal编程技术网

Objective c 我需要帮助将UIPinchGestureRecognitor子类化,以便在挤压过程中找到触摸的位置

Objective c 我需要帮助将UIPinchGestureRecognitor子类化,以便在挤压过程中找到触摸的位置,objective-c,cocos2d-iphone,box2d,uigesturerecognizer,uipinchgesturerecognizer,Objective C,Cocos2d Iphone,Box2d,Uigesturerecognizer,Uipinchgesturerecognizer,我需要跟踪触摸的位置,同时用户捏着做一些与缩放无关的游戏中的奇幻片段。我可以检测到挤压,但在挤压过程中找不到抽头的位置,只有中点(即使使用私有变量touch也不起作用) 理想的结果是(其中Box2DPinchRecognizer是我的UIPinchRecognizer子类的名称): Where Touchs是两个CGPoints的数组,指示手指的位置。无需对任何内容进行子类化。您应该能够询问任何UIgestureRecognitor在其动作方法中当前触摸的位置: - (void)pinchGes

我需要跟踪触摸的位置,同时用户捏着做一些与缩放无关的游戏中的奇幻片段。我可以检测到挤压,但在挤压过程中找不到抽头的位置,只有中点(即使使用私有变量touch也不起作用)

理想的结果是(其中Box2DPinchRecognizer是我的UIPinchRecognizer子类的名称):


Where Touchs是两个CGPoints的数组,指示手指的位置。

无需对任何内容进行子类化。您应该能够询问任何
UIgestureRecognitor
在其动作方法中当前触摸的位置:

- (void)pinchGesture:(UIGestureRecognizer *)recognizer
{
    NSUInteger numberOfTouches = recognizer.numberOfTouches;
    NSMutableArray *touchLocations = [NSMutableArray arrayWithCapacity:numberOfTouches];
    for (NSInteger touchIndex = 0; touchIndex < numberOfTouches; touchIndex++) {
        CGPoint location = [recognizer locationOfTouch:touchIndex inView:self.view];
        [touchLocations addObject:[NSValue valueWithCGPoint:location]];
    }
    ...
}
-(void)pinchGesture:(UIgestureRecognitor*)识别器
{
NSUInteger NumberOfTouchs=识别器。NumberOfTouchs;
NSMutableArray*touchLocations=[NSMutableArray阵列容量:numberOfTouchs];
对于(NSInteger touchIndex=0;touchIndex


编辑:
在代码末尾添加了方括号。

我的自定义UIPinchGestureRecognitor的第一部分为您提供了两个触摸的位置。也许它可以帮助:

请注意,我不知道每次执行该方法时触摸的顺序是否相同(即,如果一次触摸始终具有相同的索引,只要它不停止)。我很想知道情况是否如此。
- (void)pinchGesture:(UIGestureRecognizer *)recognizer
{
    NSUInteger numberOfTouches = recognizer.numberOfTouches;
    NSMutableArray *touchLocations = [NSMutableArray arrayWithCapacity:numberOfTouches];
    for (NSInteger touchIndex = 0; touchIndex < numberOfTouches; touchIndex++) {
        CGPoint location = [recognizer locationOfTouch:touchIndex inView:self.view];
        [touchLocations addObject:[NSValue valueWithCGPoint:location]];
    }
    ...
}