创建缩略图库的最佳方式

发布于 2024-12-24 03:48:35 字数 921 浏览 2 评论 0原文

我正在创建一个显示图像对象缩略图的应用程序。 (该应用程序仅适用于 iPad)

每个图像对象都显示以下信息:

  1. 图像名称

  2. 照片价格

  3. 收藏夹图标

  4. A用于选择图像的按钮(图像实际上是一个按钮,按钮的背景就是图像)。图像是从 URL 加载的。

我已经像这样绘制了这些:

  1. 创建了一个自定义视图,其中包含图像、按钮、收藏夹图标和价格标签。

  2. 加载容器视图时,我会循环绘制所有这些视图。

  3. 所有视图都绘制到 UIScrollView 中。

当视图最初加载到纵向视图中时,这一切都运行良好。

我试图确定当设备从纵向切换到横向时布局所有视图的最佳/最佳方式。

我想到的处理方法如下:

  1. 当设备切换时,完全擦除视图并重新加载所有内容。
  2. 加载视图后,将它们添加到保存数组中。当设备旋转时,循环遍历数组并更改每个视图的帧。
  3. 在每个视图中,都有两个属性。保留肖像和风景框架的属性。当设备旋转时调用reloadInputViews/ViewNeedsLayout/setNeedsLayout。

我的担忧:

  1. 这会非常慢。

  2. 将所有这些对象添加到数组中将很难占用内存。

  3. 如果调用 ViewNeedsLayout/setNeedsLayout/reloadInputViews 时对象未存储在数组中,我是否会丢失对象。

- 一如既往,非常感谢您的帮助和您的时间。

I am in the process of creating an app that shows a thumbnail view of image objects. (The app is on iPad only).

The image objects show the following information with each one:

  1. Image name

  2. Price of photo

  3. Favorite icon

  4. A button for selecting the image (which the image is actually a button, with the background of the button being the image). Image is loaded from a URL.

I have gone about drawing these like so:

  1. Created a custom view that contains the image, button, favorite icon, and price label.

  2. When the container view is loaded, I draw all of these views out in a loop.

  3. All of the views are drawn into a UIScrollView.

This is all works fine and dandy when the view is initially loaded in Portrait view.

I am trying to determine the best/optimal way to layout all of the views when the device is switched from Portrait to Landscape.

The ways that I have thought to handle this is as follows:

  1. When the device is switched, completely wipe the view and reload everything.
  2. As the views are loaded, add them to an holding array. When the device is rotated, cycle through the array and change the frames of each view.
  3. In each view, have two properties. A property that holds their frame for portrait and landscape. When the device is rotated call reloadInputViews/ViewNeedsLayout/setNeedsLayout.

My concerns:

  1. This would be really slow.

  2. Adding all of these objects to an array would be hard on memory usage.

  3. Would I loose the objects if they are not stored in an array when ViewNeedsLayout/setNeedsLayout/reloadInputViews is called.

-As always, that you for your help and your time is very much appreciated.

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

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

发布评论

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

评论(1

邮友 2024-12-31 03:48:35

我过去曾使用 KKGridView 来实现此目的,发现它非常灵活且响应迅速。它的工作原理与 UITableView 相同,并且非常高效。我刚刚出于自己的目的编辑了单元格绘图方法。

您的担忧是完全正确的 - 如果视图位于屏幕外,这会很慢并且在内存不足的情况下容易出现错误。幸运的是,KKGridView 可以为您解决这些问题。

I've used KKGridView for this in the past and found it to be wonderfully flexible and responsive. It works with the same mechanics as a UITableView and is very efficient. I've just edited the cell drawing methods for my own purposes.

Your concerns are totally valid - this would be slow and prone to bugs in low-memory conditions if the view is offscreen. Luckily, KKGridView takes care of these issues for you.

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