2016-06-27 16 views
0

x軸に日付ラベルを使用し、カスタムビューを使用して特定の日付をハイライトしたいとします。軸の範囲が変更されたとき、私はplotSpacewillChangePlotRangeToForCoordinateから呼び出されたときに、私はラベルの座標を取得する方法(core plot Framework - How to set custom UIView in CPTPlotSpaceAnnotationにsimillar)(plotSpacewillChangePlotRangeToForCoordinate:に注釈を移動)、axis:labelWasSelected:を使用したラベルの位置にannotationFrameを移動し、それをスクロールするCoreplot - 軸ラベルの座標とサイズ

を予定しておりますか!

enter image description here

EDIT: 私は成功し、ユーザーの選択によって呼び出された注釈を動かす実施している:私は_selectedLabelを保存し、プロットの範囲が変化したときにNEWFRAMEを送信します。注釈付きのラベルが画面を離れると、_selectedLabelは「忘れられた」されhttps://www.youtube.com/watch?v=R66ew6GAiJU&feature=youtu.be

  • : - 映画を見注釈枠の

    1. 遅延範囲を変更:ザ・はそれで2つの問題です。おそらく新しいラベルが作成され、古いオブジェクト - >フレームへの私の_selectedLabelの参照は、x = 0(画面を離れた点)のままです。多分特定のラベル(dateToAnnotateとの比較に基づいて)の座標を取得することは可能ですか?

      -(void)axis:(CPTAxis *)axis labelWasSelected:(CPTAxisLabel *)label { 
           NSLog(@"labelWasSelected: %@",label); 
           _selectedLabel = label; 
           CGRect graphLabelFrame = [self adjustAnnotationFrameForLabel:_selectedLabel]; 
           [_delegate datesPlot:self didAnnotateFrame:graphLabelFrame animating:YES]; 
          } 
      
      -(CPTPlotRange *)plotSpace:(CPTPlotSpace *)space willChangePlotRangeTo:(nonnull CPTPlotRange *)newRange forCoordinate:(CPTCoordinate)coordinate { 
          CGRect graphLabelFrame = [self adjustAnnotationFrameForLabel:_selectedLabel]; 
          [_delegate datesPlot:self didAnnotateFrame:graphLabelFrame animating:NO]; 
      } 
      

    と委任で

    -(void)datesPlot:(datesPlot*) plot didAnnotateFrame:(CGRect)frame animating:(BOOL)animating{ 
        if (animating) { 
        [UIView animateWithDuration:0.3 animations:^{ 
         _annotationView.frame = [self.view convertRect:frame fromView:_datesHostingView]; 
        }]; 
        } 
        else { 
         _annotationView.frame = [self.view convertRect:frame fromView:_datesHostingView]; 
        } 
    
        [_annotationView setNeedsLayout]; 
    } 
    

    EDIT2: adjustAnnotationは - 間隔を追加し、それが親ビューの座標に変換されます後に、デリゲートによってsetNeedLayoutと呼ばれる座標グラフにフレームを変換します。

    -(CGRect)adjustAnnotationFrameForSelectedLabel { 
        NSLog(@"selected Label:\n %@", _selectedLabel); 
        float annotationMargin = 20; 
        CGRect labelFrame = _selectedLabel.contentLayer.frame; 
        NSLog(@"labelframe: x: %f, y: %f", labelFrame.origin.x, labelFrame.origin.y); 
        //add margin for annotation to label's frame 
        CGRect annotationFrame = CGRectMake(labelFrame.origin.x-annotationMargin/2, labelFrame.origin.y-annotationMargin/2, 
                 labelFrame.size.width+annotationMargin, labelFrame.size.height+annotationMargin); 
        // convert from plot area coordinates to graph (and hosting view) coordinates 
        CGRect graphLabelFrame = [self.graph convertRect:annotationFrame fromLayer:self.graph.plotAreaFrame.plotArea]; 
        NSLog(@"graphLabelFrame: x: %f, y: %f", graphLabelFrame.origin.x, graphLabelFrame.origin.y); 
        return graphLabelFrame; 
    
    } 
    
  • +0

    リンクを確認してください。http://stackoverflow.com/questions/19886928/willchangeplotrangeto-makes-no-difference-to-graphs-in-core-plot –

    答えて

    1

    -axis:labelWasSelected:メソッドの2番目のパラメータは軸ラベルです。ラベルのcontentLayerは、実際にラベルを表示するサブクラスであるCALayerです。組み込みの座標変換方法を使用して、contentLayerframeおよび/またはboundsを注釈のannotationHostLayerの座標スペースに変換します。

    +0

    あなたのソリューションは機能しましたが、まだいくつか問題があります。してください、編集を参照してください。 – izik461

    +0

    1. '-adjustAnnotationFrameForLabel:'はラベルレイヤー上で '-layoutIfNeeded'を呼び出して' frame'が読み込まれる前に最新であることを確認しますか? –

    +0

    2. Core Plotラベルポリシーでは、ラベルが表示されなくなったときにラベルを削除してメモリを節約します。ラベルがどこにあるかをより詳細に制御するには、「なし」または「位置指定」ポリシーを使用できます。それ以外の場合は、「willChange」デリゲートメソッドの新しいプロット範囲を参照してください。アノテーションの場所がその範囲外の場合は、非表示にします。プロット範囲に戻った場合は、各ラベルの 'tickLocation'を見て、注釈の位置に一致するものを探します。 –

    関連する問題