Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.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

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
Ios Xcode UIScrollView缩放与MKMapView缩放相同(对子视图没有影响)_Ios_Objective C_Uiscrollview_Mkmapview_Zooming - Fatal编程技术网

Ios Xcode UIScrollView缩放与MKMapView缩放相同(对子视图没有影响)

Ios Xcode UIScrollView缩放与MKMapView缩放相同(对子视图没有影响),ios,objective-c,uiscrollview,mkmapview,zooming,Ios,Objective C,Uiscrollview,Mkmapview,Zooming,我想在我的UIScrollView上添加缩放效果。我已经通过UIScrollViewdelegate方法实现了它 (UIView*)视图用于缩放CrollView:(UICrollView*)滚动视图 现在我想添加MKMapView的效果,即如果我们放大或缩小地图的MKMapView位置标记,它将保持在相同的位置和大小。如何使用UIScrollViewzoom效果实现相同的效果 我最初的猜测是使用CGAffineTransform。但问题是什么时候以及如何 谢谢, Jay Stepin。如果我理

我想在我的
UIScrollView
上添加缩放效果。我已经通过
UIScrollView
delegate方法实现了它

(UIView*)视图用于缩放CrollView:(UICrollView*)滚动视图

现在我想添加
MKMapView
的效果,即如果我们放大或缩小地图的
MKMapView
位置标记,它将保持在相同的位置和大小。如何使用
UIScrollView
zoom效果实现相同的效果

我最初的猜测是使用
CGAffineTransform
。但问题是什么时候以及如何

谢谢,
Jay Stepin。

如果我理解正确,您希望能够放大和缩小滚动视图,同时滚动视图上的所有可视对象都保持“锚定”到它们的位置。我建议您使用
UIScrollView
zoomScale
属性,它告诉您应该应用于滚动视图内容位置的乘数

比如说,最初您有一些对象(
UIImage
,例如),其
中心位于
x=100.0
y=100.0
zoomScale=1.0
。定义两个常量/变量以将这些坐标存储在某处(例如,让我们称它们为
initialX
initialY
)。然后在
UIScrollViewDelegate
协议的
-scrollViewDidZoom:
方法中跟踪
zoomScale
值,只需将初始(非当前!)坐标与
zoomScale
的值相乘即可

例如(根据您的代码进行调整):


希望这能有所帮助。

好吧,我记下你的答案,这也是解决办法。但在我的例子中,我通过重新调整帧来处理它,而不是仅仅移动中心。
#pragma mark - UIScrollViewDelegate

- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
    CGFloat currentScale = scrollView.zoomScale;

    // Adjust object's position.
    CGPoint currentCenter = yourObject.center;

    currentCenter.x = initialX * currentScale;
    currentCenter.y = initialY * currentScale;

    yourObject.center = currentCenter;
}