2012-02-01 7 views
2

私は、いくつかの行を表示する簡単なチャートコントロールを持っています。グラフの絵に関わる3つのプロパティがあります。UIPinchGestureRecognizer正しい使い方は?

  • RecordCount
  • FirstVisibleIndex
  • LastVisibleIndex

すべてがOK、チャートはまず&最終可視録音の間だけで罰金を描いて動作します。 今私は&を2本の指でチャートにズームアウトさせたいので、私はUIPinchGestureRecognizerを購読してそのようなルーチンを実装しました。

-(void)handleZoomGesture:(UIGestureRecognizer *)sender 
{ 
    if (_isChartBusy) { 
     return; 
    } 

    UIPinchGestureRecognizer *gr = (UIPinchGestureRecognizer*)sender; 
    if (gr.state != UIGestureRecognizerStateChanged && gr.state != UIGestureRecognizerStateEnded) 
     return; 

    CGFloat scale = gr.scale; 
    if (scale == 1) { 
     return ; 
    } 

    if (_prevZoomScale == 0) { 
     _prevZoomScale = scale; 
     return; 
    } 

    int startIndex = chart.FirstVisibleIndex; 
    int endIndex = chart.LastVisibleIndex; 

    NSLog(@"Zoom. Scale: %f", scale); 
    int stepZoom; 
    int cnt = chart.LastVisibleIndex - chart.FirstVisibleIndex; 
    stepZoom = cnt * 0.05; 


    if (scale < _prevZoomScale) { 
     startIndex -= stepZoom; 
     endIndex += stepZoom; 
    } else { 
     startIndex += stepZoom; 
     endIndex -= stepZoom; 
    } 

    _prevZoomScale = scale; 

    if (endIndex < startIndex || (endIndex - startIndex) < 10) { 
     return; 
    } 

    if (startIndex < 0) { 
     startIndex = 0; 
    } 

    if (endIndex >= [chart.DataProvider GetBarRecordCount]) { 
     endIndex = [chart.DataProvider GetBarRecordCount] - 1; 
    } 

    if (startIndex == chart.FirstVisibleIndex && endIndex == chart.LastVisibleIndex) { 
     return; 
    } 

    chart.FirstVisibleIndex = startIndex; 
    chart.LastVisibleIndex = endIndex; 
    [self setNeedsDisplay]; 
} 

それはちょっと動作しますが、私は指を動かすと、ズーム操作を行うためにしようとすると非常に不安定、チャートは「びくびく」を取得します。 &の経験があり、すてきで滑らかなズームをシミュレートできません。 VisibleIndexesのようなスムーズな変更を実現するための最良の方法は、チャート内のレコード数と表示可能なレコード数に関連します。

答えて

1

私が最初に行うことは、パフォーマンスのためにアニメーションをグラフ化し、どのレイヤーが問題を引き起こしているかを調べることです。 Core Animationツールを使用してInstrumentsのデバイスで実行してみてください。次に、混色したレイヤーを有効にして、赤色がどれだけ見えるかを確認します。

コアアニメーションのパフォーマンスの最適化に関するチュートリアルをご覧ください。 http://mobileoverlord.com/instruments-optimizing-core-animation/

+0

質問は、パフォーマンスについては、チャート塗料はかなり高速です。私の問題は、スムーズなズームイン&アウトエクスペリエンスを実現するために、ジェスチャーコールバック内にあるチャートプロパティを正しく操作する方法です。 – Eugen

+0

何をチャートに使用していますか?あなたはCore Graphicsで直接描画していますか – MobileOverlord

+0

はい、私はQuartzを使って描画しますが、それは描画に関するものではありません。ジェスチャーコールバックで取得した値を使用してプロパティ(FirstVisibleIndex、LastVisibleIndex)を正しく計算する方法です。 – Eugen

関連する問題