我需要使用捏识别器调整我的绘图大小,它允许在左侧和底部的小区域中分别调整“宽度”和“高度”的大小。我的情节也在 UIScrollView 内部以水平滚动
这是我的 Y 轴捏代码:
- (void)yAxisPinchPerformed:(UIPinchGestureRecognizer *)pinchRecognizer
{
CGFloat recognizerScale = pinchRecognizer.scale;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)_graph.defaultPlotSpace;
switch (pinchRecognizer.state) {
case UIGestureRecognizerStateBegan:
{
_savedRange = plotSpace.yRange;
}
break;
case UIGestureRecognizerStateChanged:
{
CGFloat scaledRange = recognizerScale * _savedRange;
[plotSpace setYRange:scaledRange];
}
break;
default:
break;
}
}
效果很好,但在设备上真的很慢,可能是因为它重绘了整个情节(它很宽并且在 UIScrollView 内部),而不仅仅是可见区域;我的情节包含最多 100 条渐变填充。我试图关闭填充,但它只起到了一点作用;
现在我有这些改进:
- (void)yAxisPinchPerformed:(UIPinchGestureRecognizer *)pinchRecognizer
{
CGFloat recognizerScale = pinchRecognizer.scale;
switch (pinchRecognizer.state) {
case UIGestureRecognizerStateBegan:
{
// UIImageView *_imageView;
[_imageView setImage:_graph.imageOfLayer];
[_imageView setHidden:NO];
// CGRect initialFrame is frame of graph container
[_imageView setFrame:initialFrame];
_savedHeigth = _imageView.frame.size.height;
}
break;
case UIGestureRecognizerStateChanged:
{
CGFloat scaledHeight = recognizerScale * _savedHeight;
CGRect imageFrame = _imageView.frame;
imageFrame.size.height = scaledHeight;
[_imageView setFrame:imageFrame];
}
break;
case UIGestureRecognizerStateEnded:
CGFloat scaledRange = calculateRangeFromHeights(...);
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)_graph.defaultPlotSpace;
[plotSpace setYRange:scaledRange];
[_imageView setHidden:YES];
break;
default:
break;
}
}
我得到绘图层的图像并执行 UIImageView 的缩放,它超级快。但是当我减小 Y 比例时,我只有部分图形,它在顶部被切割。
是否可以平滑实时地缩放 Core Plot 图?