在 Objective C 中绘制图像和文本最简单的方法是什么?

发布于 2024-10-15 11:02:48 字数 182 浏览 0 评论 0原文

我正计划实现一个类似于iPhone相册的组件。我想使用uviews会使该组件的性能很差,我的意思是滚动缓慢以及所有这些东西......所以我应该采取哪种方式? CALayer 在性能方面比 UIViews 更好吗?还有其他(更轻的)方法吗 不使用 UIView 子类来绘制图像或文本?

任何链接或想法都会很棒,

谢谢!

I am planning to implement a component similar to the iphone's photo album.. I guess that using uviews will make the component to have a bad performace , I mean scrolling slow and all of the stuff ... so which way should I take?
Is CALayer better than UIViews in terms of performance? Is there any other (lighter) way
to draw images or text without using UIView subclasses?

Any link or idea will be great,

Thanks you!

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

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

发布评论

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

评论(2

℉絮湮 2024-10-22 11:02:48

有很多关于图形以及 UIView 与绘图的优缺点的教程。我不是专家,但我怀疑性能更可能来自您的实例化和缓存策略。也就是说,如果您想要快速滚动,那么考虑最大限度地减少实例化对象的数量,缓存和重用这些对象以及用于加载数据的有效块加载例程都会产生巨大的好处。

但我倾向于先做一个简单的概念验证应用程序,将其加载到设备上,看看它的速度有多快以及您最有可能需要解决性能问题的地方。除了缓存和重用组件等标准设计策略之外,在确定出现性能瓶颈的位置之前尝试优化性能通常不是一个好主意。

There are plenty of tutorials about graphics and the pros and cons of UIView vs drawing. I'm no expert but I suspect that performance is more likely to come from your instantiation and caching strategies. I.e. if you want fast scrolling then looking at minimising the number of objects instantiated, caching and reusing those that are and an effective block loading routine for loading data will all yield large benefits.

But I'd be inclined to do a simple proof of concept app first, load it onto a device and see how fast it goes and where you are most likely to need to address performance issues. Apart from standard design strategies such as caching and reusing components, attempting to optimize the performance before you have identified where the performance bottlenecks are occurring is generally not a good idea.

香橙ぽ 2024-10-22 11:02:48

如果您只是重新发明现有的系统实现,请从使用系统的实现开始,然后看看此时的具体问题是什么。

如果您有一些非常专业的东西或者使用 UIView 不容易实现的东西,请查看 CoreGraphics.framework 和 CoreText.framework。

高级库中的大部分绘图和动画都使用 CoreGraphics 技术。然而,它们通常是简化的或更高级别的,并且可能包含特定的抽象成本。 cg 渲染不适合新手 - 如果您不了解 UIKit/AppKit 渲染,您可能会花费大量时间来学习它,并且它不一定是对 UIKit/AppKit 实现的改进。如果您对 UIView/NSView 和图形非常熟悉,那么您的自定义绘图将会有很多收获。

(我假设您不会使用此方法进入 OpenGL 层)

“猜测使用 uiviews 会使组件性能不佳”可能不是一个好主意。如果实现已经存在,请相信 Apple 已经花费了一些时间对其进行优化 - 在开发特定于您的需求的改进的过程中,您将有一些时间投入并获得潜在的知识。我建议你从你已经熟悉的内容开始,然后确定它是否需要改进——你甚至可以在 UIView/NSView 中使用 CG 渲染,这样你就不一定需要重新创建 UIView 的替代品。既然你在OP中没有提到CoreGraphics,我猜你对它不是很熟悉。

祝你好运

if you'd just reinvent an existing system implementation, start by using the system's implementation and see what the specific issues are from that point.

if you've something very specialized or not easily achieved with UIView, look into CoreGraphics.framework and CoreText.framework.

much of the drawing and animation in higher level libs use the CoreGraphics technologies. however, they are often simplified or higher level and may contain specific abstraction costs. cg rendering is not for the novice - if you don't understand UIKit/AppKit rendering, you're likely to lose a lot of time learning it, and it will not necessarily be an improvement upon the UIKit/AppKit implementations. if you are very comfortable with UIView/NSView and graphics, there's a lot to gain for your customized drawing.

(i'm assuming you aren't going to the OpenGL layer with this)

it may not be a good idea to 'guess that using uiviews will make the component to have a bad performance'. if the implementation is already there, trust that Apple's spent some time optimizing it -- you will have some time to invest and potentially knowledge to acquire in the process of developing an improvement specific to your needs. i'd recommend you start with what you're already familiar with and then determine whether it needs improvement -- you can even use CG rendering within UIView/NSView so you will not necessarily need to recreate a replacement for UIView. since you didn't mention CoreGraphics in the OP, i'm guessing you're not very familiar with it.

good luck

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