drawRect 使 UIScrollView 中的滚动速度变慢

发布于 2024-11-07 16:01:25 字数 263 浏览 2 评论 0原文

我有一个 UIScrollView,里面有一个(自定义)UIView。

我调用

[myCustomView setNeedsDisplay];

在我的scrollViewDidScroll方法中,如果我在自定义UIView中实现drawRect:方法,

这会使滚动明显变慢 - 即使它完全是空的。一旦我删除了drawRect:方法,一切又变得顺利了。

我完全不知道,为什么……你们中的任何一个人?

I've got a UIScrollView with a (custom) UIView inside of it.

In my scrollViewDidScroll-method I'm calling

[myCustomView setNeedsDisplay];

This makes the scrolling noticeably slower, if I'm implementing the drawRect: method in my custom UIView - even if it's completely empty.

As soon as I delete the drawRect: method, it's smooth again.

I have absolutely no idea, why... anyone of you?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

-小熊_ 2024-11-14 16:01:25

我也讨厌drawrect

“这是因为Cocoa中硬件加速动画的工作方式。

如果你没有自定义的drawRect方法,系统会在视频内存中缓存视图的像素。当需要重绘它们时,它只是将像素传输到屏幕上。

如果您有自定义的drawRect方法,则系统必须调用您的drawRect方法来渲染主内存中的像素,然后将这些像素复制到视频内存中,然后将像素绘制到屏幕上。每一个文档说,如果可以的话,请避免使用drawRect,

为视图实现drawRect方法时,系统仍然有很多工作要做。

我认为大多数/所有iOS设备上都共享主内存和视频内存,但是当您 使用 OpenGL 层并通过 OpenGL 调用进行渲染可能会更好,因为 OpenGL 直接与显示硬件对话。”

链接到该引用: http: //www.iphonedevsdk.com/forum/iphone-sdk-development/80637-drawrect-makes-scrolling-slow-uiscrollview.html

I hate drawrect too

"It's because of the way hardware-accellerated animation works in Cocoa.

If you don't have a custom drawRect method, the system caches the pixels for your view in video memory. When it needs to redraw them, it just blits the pixels onto the screen.

If you have a custom drawRect method, the system instead has to call your drawRect method to render the pixels in main memory, then copy those pixels into video memory, THEN draw the pixels to the screen for each an every frame. The docs say to avoid drawRect if you can.

I think main memory and video memory are shared on most/all iOS devices, but the system still has a lot more work to do when you implement a drawRect method for a view.

You would probably be better served to use an OpenGL layer and render to that with OpenGL calls, since OpenGL talks directly with the display hardware."

link to that quote: http://www.iphonedevsdk.com/forum/iphone-sdk-development/80637-drawrect-makes-scrolling-slow-uiscrollview.html

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