我创建了自己的解决方案,可以在不缩放整个场景的情况下对特定的SKNode进行缩放,它似乎大部分按照我的预期工作,但有两个显著的例外,希望在这里得到帮助。首先,这是代码(该控制语句位于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被缩放时,虽然尺寸发生了改变,但是效果并不总是像我期望的那样平滑,存在一些抖动,让人感到很烦恼。