【发布时间】:2023-04-04 00:00:01
【问题描述】:
我从事地图替换工作已经有一段时间了。整个过程与 UIScrollView 一起工作,并由 CATiledLayer 支持。
要旋转我的地图,我会旋转图层本身。 (使用CATransform3DMakeRotation)到目前为止效果很好=)
但是,如果我调用 setZoomScale 方法,将提交到我的图层的 CATransform3D 会将旋转重置为 0。
我的问题是,有什么方法可以设置我的滚动视图的 zoomscale 而不会丢失应用的旋转?
捏合手势也存在同样的问题。
//附加信息
要围绕当前位置旋转,我必须编辑锚点。也许这也是缩放的问题。
- (void)correctLayerPosition {
CGPoint position = rootView.layer.position;
CGPoint anchorPoint = rootView.layer.anchorPoint;
CGRect bounds = rootView.bounds;
// 0.5, 0.5 is the default anchorPoint; calculate the difference
// and multiply by the bounds of the view
position.x = (0.5 * bounds.size.width) + (anchorPoint.x - 0.5) * bounds.size.width;
position.y = (0.5 * bounds.size.height) + (anchorPoint.y - 0.5) * bounds.size.height;
rootView.layer.position = position;
}
- (void)onFinishedUpdateLocation:(CLLocation *)newLocation {
if (stayOnCurrentLocation) {
[self scrollToCurrentPosition];
}
if (rotationEnabled) {
CGPoint anchorPoint = [currentConfig layerPointForLocation:newLocation];
anchorPoint.x = anchorPoint.x / rootView.bounds.size.width;
anchorPoint.y = anchorPoint.y / rootView.bounds.size.height;
rootView.layer.anchorPoint = anchorPoint;
[self correctLayerPosition];
}
}
【问题讨论】:
标签: ios uiscrollview rotation calayer zooming