2012-08-17 4 views
6

私はかなり長い間マップの置換に取り組んできました。全体はUIScrollViewで、CATiledLayerに裏打ちされています。UIScrollView setZoomScaleは、適用された回転を0に戻します。

マップを回転するには、レイヤー自体を回転させます。 (CATransform3DMakeRotationを使用して)今のところかなりうまく動作します=)

しかし、私は今まで私の層に提出されようとしているCATransform3Dは、私の質問は、ありさ0

に回転をリセットしてsetZoomScaleメソッドを呼び出す場合適用された回転を失うことなく、私のscrollViewの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]; 
    } 
} 

答えて

7

あなたはscrollViewDidZoom:デリゲートメソッドを実装し、所望の効果を達成するために2つの変換を連結することができます:私はシンプルなアイデアを持っている

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

    contentView.layer.transform = CATransform3DConcat(rotation, scale); 
} 

EDIT

を!ローテーション変換が適用された別のビューを階層に追加する方法はありますか?ここで提案した階層です:

  • ScrollViewは
    • ContentView - viewForZoomingInScrollView:
      • RotationViewによって返さ1 - 回転と1が
        • のMapViewを変換する - すべてのタイルで1

パフォーマンスはここでは心配する必要はありませんし、試してみる価値があります。

+0

ちょっとBartosz、まず、そのポストに感謝します!しかし、それは私のためには機能しませんでした...私はアンカーポイントを編集して現在の位置を中心に回転させました。多分それは問題ですか?投稿を編集してそのコードを追加します。 –

+0

それは回転を保持しましたが、回転軸が間違っていました。 –

+0

私は本当に分からない。ちょうど私が見るものから、それは奇妙な点の周りに多く回転します。しかし、軸は正しいようです。 –

関連する問題