gpt4 book ai didi

ios - Coreplot - 轴标签的坐标和大小

转载 作者:行者123 更新时间:2023-11-29 00:51:48 27 4
gpt4 key购买 nike

我在 x 轴上使用日期标签,并希望使用自定义 View 突出显示特定日期。我计划使用 axis:labelWasSelected: ,将annotationFrame移动到标签位置并在轴范围更改时滚动它(在 plotSpacewillChangePlotRangeToForCoordinate: 中移动注释)(类似于 core plot Framework - How to set custom UIView in CPTPlotSpaceAnnotation )

从 plotSpacewillChangePlotRangeToForCoordinate 调用时如何获取标签的坐标?

enter image description here

编辑:我已经成功实现了由用户选择调用的移动注释:我保存 _selectedLabel 并在绘图范围发生变化时发送 newFrame。有两个问题:

  1. 更改范围时注释框的延迟 - 看电影:https://www.youtube.com/watch?v=R66ew6GAiJU&feature=youtu.be

  2. 当带注释的标签离开屏幕时,_selectedLabel 被“遗忘”。当移回屏幕时,可能会创建新标签,并且我对旧对象->框架的 _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];
    }

在委托(delegate)中:

-(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];
}

编辑2:adjustmentAnnotation - 添加间距并将框架转换为图形坐标 setNeedLayout 在转换为父 View 的坐标后由委托(delegate)调用。

-(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;

}

最佳答案

-axis:labelWasSelected: 方法的第二个参数是轴标签。标签的contentLayer是一个实际显示标签的CALayer子类。使用内置的坐标转换方法将 contentLayerframe 和/或 bounds 转换为注释的 的坐标空间annotationHostLayer.

关于ios - Coreplot - 轴标签的坐标和大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38053247/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com