x軸に日付ラベルを使用し、カスタムビューを使用して特定の日付をハイライトしたいとします。軸の範囲が変更されたとき、私はplotSpacewillChangePlotRangeToForCoordinateから呼び出されたときに、私はラベルの座標を取得する方法(core plot Framework - How to set custom UIView in CPTPlotSpaceAnnotationにsimillar)(plotSpacewillChangePlotRangeToForCoordinate:
に注釈を移動)、axis:labelWasSelected:
を使用したラベルの位置にannotationFrameを移動し、それをスクロールするCoreplot - 軸ラベルの座標とサイズ
を予定しておりますか!
EDIT: 私は成功し、ユーザーの選択によって呼び出された注釈を動かす実施している:私は_selectedLabel
を保存し、プロットの範囲が変化したときにNEWFRAMEを送信します。注釈付きのラベルが画面を離れると、_selectedLabel
は「忘れられた」されhttps://www.youtube.com/watch?v=R66ew6GAiJU&feature=youtu.be
: - 映画を見注釈枠の
遅延範囲を変更:ザ・はそれで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;
}
リンクを確認してください。http://stackoverflow.com/questions/19886928/willchangeplotrangeto-makes-no-difference-to-graphs-in-core-plot –