如果视图宽度大于 16600,UIView 中的绘图将停止工作

发布于 2024-10-04 22:56:39 字数 539 浏览 0 评论 0原文

我正在使用以下代码在视图中绘制图形(在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

野侃 2024-10-11 22:56:39

为视图设置如此大的宽度是非常糟糕的主意,您必须只绘制用户一次(或多一点)可以看到的内容,并为此使用正常(屏幕)大小的视图。要控制用户当前所在的位置,请使用 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.

无语# 2024-10-11 22:56:39

您可能最好使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文