我必须制作如下图:
以某种方式使用bezierPath,CAShapeLayer和动画我设法制作图表。但现在想要添加缩放功能。缩放代码如下:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return _graphView;
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollV withView:(UIView *)view atScale:(CGFloat)scale
{
[_scrollView setContentSize:CGSizeMake(scale*320, scale*1700)];
}
当我水平滚动时,一切正常,但垂直方向请查看下图:
注意:X和Y轴在视图上,图形在滚动视图上,我还想根据缩放更改x和y坐标,并使其可滚动。任何帮助或建议将不胜感激。
答案 0 :(得分:0)
请参阅以下内容:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
CGFloat offsetX = MAX((scrollView.bounds.size.width - scrollView.contentSize.width) * 0.5, 0.0);
CGFloat offsetY = MAX((scrollView.bounds.size.height - scrollView.contentSize.height) * 0.5, 0.0);
_drawingView.center = CGPointMake(scrollView.contentSize.width * 0.5 + offsetX,
scrollView.contentSize.height * 0.5 + offsetY);
return _drawingView;
}