UIScrollView setZoomScale将应用的旋转设置回零

6 rotation zooming calayer uiscrollview ios

我已经在相当长一段时间内更换地图了.整个事情与一个UIScrollView支持CATiledLayer.

要旋转我的地图,我会旋转图层本身.(使用CATransform3DMakeRotation)到目前为止工作得很好=)

但是如果我要调用setZoomScale方法CATransform3D是将被提交给我的层重新旋转为0.

我的问题是,有没有办法设置zoomscale我的scrollView而不会失去应用的旋转?

捏手势存在同样的问题.

//其他信息

要围绕当前位置旋转,我必须编辑锚点.也许这也是缩放的问题.

- (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];
    }
}
Run Code Online (Sandbox Code Playgroud)

Bar*_*ski 7

您可以实现scrollViewDidZoom:委托方法并连接两个转换以实现所需的效果:

- (void) scrollViewDidZoom:(UIScrollView *) scrollView
{
    CATransform3D scale = contentView.layer.transform;
    CATransform3D rotation = CATransform3DMakeRotation(M_PI_4, 0, 0, 1);

    contentView.layer.transform = CATransform3DConcat(rotation, scale);
}
Run Code Online (Sandbox Code Playgroud)

编辑

我有更简单的想法!如何在附加了旋转变换的情况下向层次结构中添加另一个视图?这是建议的层次结构:

  • 滚动型
    • ContentView - 返回的那个 viewForZoomingInScrollView:
      • RotationView - 具有旋转变换的那个
        • MapView - 包含所有图块的图块

我认为这里的表现不应该受到任何关注,值得一试.