如果视图宽度大于 16600,UIView 中的绘图将停止工作
我正在使用以下代码在视图中绘制图形(在 drawRect 方法中):
CGContextBeginPath(context);
CGContextMoveToPoint(context, devicePoint.x, devicePoint.y);
for (index = 1; index < dataCount; index++) {
devicePoint = [[deviceDataArray objectAtIndex:index] CGPointValue];
CGContextAddLineToPoint(context, devicePoint.x, devicePoint.y);
}
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextStrokePath(context);
如果 view.bounds.size.width
小于约 16600,则它可以工作。但是超过该大小,绘图将停止出现。
我根据要绘制的数据的范围调整视图的大小。
I am using following code to plot graph in a view (in the drawRect method):
CGContextBeginPath(context);
CGContextMoveToPoint(context, devicePoint.x, devicePoint.y);
for (index = 1; index < dataCount; index++) {
devicePoint = [[deviceDataArray objectAtIndex:index] CGPointValue];
CGContextAddLineToPoint(context, devicePoint.x, devicePoint.y);
}
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextStrokePath(context);
It works if the view.bounds.size.width
is less than about 16600. But above that size the plot stops appearing.
I resize the view depending on the range of the data to be plotted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为视图设置如此大的宽度是非常糟糕的主意,您必须只绘制用户一次(或多一点)可以看到的内容,并为此使用正常(屏幕)大小的视图。要控制用户当前所在的位置,请使用 UIScrollView。
This is very bad idea to make such huge width for view, you must draw only what user can see in one time (or a little more) and use view of normal (screen) size for this. For controlling where user currently is use UIScrollView.
您可能最好使用 CAShapeLayers 进行绘图,因为它们没有实际像素,只是硬件绘制的路径。然后你可以有一个 UIScrollView ,它只暴露部分 CAShapeLayers 进行绘制,否则你将制作一个巨大的图像,其视图与当前的视图一样大。
You are probably better off using CAShapeLayers to do the drawing, as they have no actual pixels, just a path that the hardware draws. Then you could have a UIScrollView which just exposed parts of the CAShapeLayers for drawing, otherwise you are making a huge image with the view as large as you have it currently.