创建缩略图库的最佳方式
我正在创建一个显示图像对象缩略图的应用程序。 (该应用程序仅适用于 iPad)。
每个图像对象都显示以下信息:
图像名称
照片价格
收藏夹图标
A用于选择图像的按钮(图像实际上是一个按钮,按钮的背景就是图像)。图像是从 URL 加载的。
我已经像这样绘制了这些:
创建了一个自定义视图,其中包含图像、按钮、收藏夹图标和价格标签。
加载容器视图时,我会循环绘制所有这些视图。
所有视图都绘制到 UIScrollView 中。
当视图最初加载到纵向视图中时,这一切都运行良好。
我试图确定当设备从纵向切换到横向时布局所有视图的最佳/最佳方式。
我想到的处理方法如下:
- 当设备切换时,完全擦除视图并重新加载所有内容。
- 加载视图后,将它们添加到保存数组中。当设备旋转时,循环遍历数组并更改每个视图的帧。
- 在每个视图中,都有两个属性。保留肖像和风景框架的属性。当设备旋转时调用reloadInputViews/ViewNeedsLayout/setNeedsLayout。
我的担忧:
这会非常慢。
将所有这些对象添加到数组中将很难占用内存。
如果调用 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:
Image name
Price of photo
Favorite icon
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:
Created a custom view that contains the image, button, favorite icon, and price label.
When the container view is loaded, I draw all of these views out in a loop.
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:
- When the device is switched, completely wipe the view and reload everything.
- 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.
- 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:
This would be really slow.
Adding all of these objects to an array would be hard on memory usage.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我过去曾使用 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.