Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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
Ios 如何在谷歌地图中实现类似缩放_Ios_Objective C_Uipinchgesturerecognizer - Fatal编程技术网

Ios 如何在谷歌地图中实现类似缩放

Ios 如何在谷歌地图中实现类似缩放,ios,objective-c,uipinchgesturerecognizer,Ios,Objective C,Uipinchgesturerecognizer,我正在开发一个带有一些游戏场的游戏,在一些视图中绘制。我的比赛场地总是和他的中锋相对,所以我只需要简单的挤压 - (void)pinch:(UIPinchGestureRecognizer *)gesture { if ((gesture.state == UIGestureRecognizerStateChanged) || (gesture.state == UIGestureRecognizerStateEnded)) { self.gameBoardGridView.sc

我正在开发一个带有一些游戏场的游戏,在一些视图中绘制。我的比赛场地总是和他的中锋相对,所以我只需要简单的挤压

- (void)pinch:(UIPinchGestureRecognizer *)gesture
{
if ((gesture.state == UIGestureRecognizerStateChanged) ||
    (gesture.state == UIGestureRecognizerStateEnded)) {
    self.gameBoardGridView.scale *= gesture.scale; // adjust our scale

    gesture.scale = 1;  
}
和潘

-(void)pan:(UIPanGestureRecognizer *)recognizer
{
CGPoint translatedPoint = [recognizer translationInView:self.gameBoardGridView];


self.gameBoardGridView.gridCenter = CGPointMake(self.gameBoardGridView.gridCenter.x + translatedPoint.x, self.gameBoardGridView.gridCenter.y + translatedPoint.y);

[recognizer setTranslation:CGPointMake(0, 0) inView:self.gameBoardGridView];
}
但我需要另一种变焦。当您放下两个手指,然后移动其中一个手指时,场会像应该的那样展开(放大),但手指下的像素不再位于手指下。图像从图像中心开始缩放,而不是从两个手指之间的中点开始缩放

我尝试了很多例子,但没有一个像我想要的那样有效。最后我写了这个,它几乎正确,但不完全正确

- (void)pinch:(UIPinchGestureRecognizer *)gesture
{
CGFloat curScale = gesture.scale;

static CGPoint startPoint;

if (gesture.state == UIGestureRecognizerStateBegan) {
    startPoint = [gesture locationInView:self.gameBoardGridView];
}


if ((gesture.state == UIGestureRecognizerStateChanged) ||
    (gesture.state == UIGestureRecognizerStateEnded)) {
    self.gameBoardGridView.scale *= gesture.scale;

    CGFloat widthDelta = self.gameBoardGridView.gridWidth * fabs(gesture.scale - 1) / 3;
    CGFloat heightDelta = self.gameBoardGridView.gridHeight * fabs(gesture.scale - 1) / 3;


    gesture.scale = 1;

    CGPoint lastPoint = self.gameBoardGridView.gridCenter;

    const CGFloat epsilon = 5;

    CGFloat coef = 1.0;
    if(curScale < 1) {
        coef = -1.0;
    }

    if (startPoint.x + epsilon < self.view.frame.size.width / 2) {
            lastPoint.x += widthDelta*coef;
    }
    else if (startPoint.x - epsilon > self.view.frame.size.width / 2) {
            lastPoint.x -= widthDelta*coef;
    }

    if (startPoint.y + epsilon < self.view.frame.size.height / 2) {
            lastPoint.y += heightDelta*coef;
    }
    else if (startPoint.y - epsilon > self.view.frame.size.height / 2) {
            lastPoint.y -= heightDelta*coef;
    }


    self.gameBoardGridView.gridCenter = lastPoint;
}
}
-(void)pinch:(UIPinchGestureRecognizer*)手势
{
CGFloat curScale=手势.scale;
静态CGPoint起始点;
if(signature.state==UIGestureRecognitizerStateStart){
startPoint=[手势位置视图:self.gameBoardGridView];
}
如果((手势.state==UIGestureRecognitizerStateChanged)||
(手势.state==UIGestureRecognitzerStateEnded)){
self.gameBoardGridView.scale*=手势.scale;
CGFloat widthDelta=self.gameBoardGridView.gridWidth*fabs(signature.scale-1)/3;
CGFloat heightDelta=self.gameBoardGridView.gridHeight*fabs(signature.scale-1)/3;
1.scale=1;
CGPoint lastPoint=self.gameBoardGridView.gridCenter;
常数CGFloatε=5;
cgf=1.0;
如果(光标<1){
coef=-1.0;
}
if(startPoint.x+epsilonself.view.frame.size.width/2){
lastPoint.x-=宽度增量*系数;
}
if(起始点y+epsilonself.view.frame.size.height/2){
lastPoint.y-=高度增量*系数;
}
self.gameBoardGridView.gridCenter=lastPoint;
}
}

可能还有其他方法可以做到这一点吗

缩放的中心是图像的定位点。 你所要做的就是将锚点改为手指的中点、位置和位置。 我自己没有试过,我在这里看到了一个完整的解决方案,也许它会帮助你-


您是否尝试过使用
UIScrollView
?我也做了类似的事情。我开始使用本教程,然后为我的应用程序添加了一些特定的代码