我已经创建了自己的解决方案,用于放大或缩小特定的 SKNode,而无需缩放整个场景,它似乎主要按照我期望的方式工作,有 2 个值得注意的例外,我希望在这里得到输入。首先是代码(该控制语句位于touchesMoved方法内):
if (touches.count == 2) {
// this means there are two fingers on the screen
NSArray *fingers = [touches allObjects];
CGPoint fingOneCurr = [fingers[0] locationInNode:self];
CGPoint fingOnePrev = [fingers[0] previousLocationInNode:self];
CGPoint fingTwoCurr = [fingers[1] locationInNode:self];
CGPoint fingTwoPrev = [fingers[1] previousLocationInNode:self];
BOOL yPinch = fingOneCurr.y > fingOnePrev.y && fingTwoCurr.y < fingTwoPrev.y;
BOOL yUnpinch = fingOneCurr.y < fingOnePrev.y && fingTwoCurr.y > fingTwoPrev.y;
BOOL xPinch = fingOneCurr.x > fingOnePrev.x && fingTwoCurr.x < fingTwoPrev.x;
BOOL xUnpinch = fingOneCurr.x < fingOnePrev.x && fingTwoCurr.x > fingTwoPrev.x;
if (xUnpinch | yUnpinch) {
if (YES) NSLog(@"This means an unpinch is happening");
mapScale = mapScale +.02;
[map setScale:mapScale];
}
if (xPinch | yPinch) {
if (YES) NSLog(@"This means a pinch is happening");
mapScale = mapScale - .02;
[map setScale:mapScale];
}
}
现在的问题是:
有时,捏合和松开并不总是正确的,当发生这种情况时,我无法完全准确地指出,捏合将表现为松开,反之亦然。
当捏合和松开正确缩放 SKNode 时,它很少像我希望的那样平滑。它有一点生涩,我觉得很烦人。
谁能建议改进这种方法?谢谢!
这将解决您的问题,感谢 Steffen 的提示。
- (void)didMoveToView:(SKView *)view
{
UIPinchGestureRecognizer *precog = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)];
[self.scene.view addGestureRecognizer:precog];
}
- (void)handlePinch:(UIPinchGestureRecognizer *) recognizer
{
//NSLog(@"Pinch %f", recognizer.scale);
//[_bg setScale:recognizer.scale];
[_bg runAction:[SKAction scaleBy:recognizer.scale duration:0]];
recognizer.scale = 1;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)