如何呈现“画廊”在ipad上?

发布于 2024-09-19 10:05:50 字数 249 浏览 5 评论 0原文

我正在为 ipad 构建一个应用程序,它使用 youtube api 来获取视频缩略图并将其呈现在图库中(就像 ipad 上的本机 youtube 应用程序一样)。基本上它只是 UIScrollView 上的一堆 UIImageView。现在的问题是,一次显示所有图像可能会导致应用程序因内存问题而崩溃,因此我们的想法是只保留可见的图像,并将其他图像写回文件。

我的问题是如何获取 UIScrollView 内容的准确“可见”区域边界。

有什么想法吗?

I'm building an app for the ipad that uses the youtube api to get the video thumbnails and present them in a gallery (like the native youtube app on the ipad). Basically it's just a bunch of UIImageViews on a UIScrollView. Now the problem is that displaying all the images at once may cause the app to crash due to memory problems, so the idea is to keep only the images which can bee seen, and write back the others to files.

My problem is how to get the exact "visible" area bounds of the content of the UIScrollView.

Any ideas?

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

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

发布评论

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

评论(5

紫罗兰の梦幻 2024-09-26 10:05:50

您看过 AQGridView 吗?它正是为此类事情而设计的。

Have you taken a look at AQGridView? It's designed for precisely this sort of thing.

巴黎夜雨 2024-09-26 10:05:50

观看 WWDC 2010 第 104 场会议 - 使用滚动视图设计应用程序。

Watch WWDC 2010 Session 104 - Designing Apps with Scroll Views.

不气馁 2024-09-26 10:05:50

当 UIScrollView 滚动时,您应该检查内容偏移量 (scrollView.contentOffset) 并获取(例如)x 值。有了这个(并且取决于 uiscrollview 的宽度框架值),您应该能够知道用户正在看到什么。尝试使用 NSLog 打印这些信息;-)

然后当您知道用户正在查看哪个“页面”时,您可以加载一些 UIImageView。

祝你好运 :-)

When UIScrollView scrolled you should check the content offset (scrollView.contentOffset) and get (for example) the x value. With that (and depending on the width frame value of your uiscrollview), you should be able to know what the user is seing. Try printing these informations with a NSLog ;-)

And then when you know which "page" the user is seing, you could load some UIImageView.

Good Luck :-)

心安伴我暖 2024-09-26 10:05:50

在layoutSubviews中,您可以像这样获取当前可见的边界:

CGRect visibleBounds = [self bounds];

然后您可以通过将其框架与visibleBounds进行比较来检查UIView(例如UIImageView)是否可见:

BOOL visible = CGRectIntersectsRect(visibleBounds,cellFrame);

只需检查每个可见视图并删除那些超出的视图的可见边界。然后检查数据集是否有可见但尚无视图的图像。

您还应该重用 UIView,而不是一直创建新的 UIView。只需将已删除的集合放入 NSSet 中进行排队,并在创建新集合之前检查该集合。

In layoutSubviews you can get the currently visible bounds like this:

CGRect visibleBounds = [self bounds];

You can then check if a UIView (e.g. UIImageView) is visible by comparing its frame with visibleBounds:

BOOL visible = CGRectIntersectsRect(visibleBounds,cellFrame);

Simply check each visible view and remove those that are outside of the visible bounds. Then check the dataset for images that are visible, but don't have a view yet.

You should also reuse UIViews instead of creating new ones all the time. Simply queue removed ones in an NSSet and check that set before creating new ones.

尘世孤行 2024-09-26 10:05:50

这是一种不同的方法:

使用 UITableView 但调整属性,使其看起来像常规滚动视图。 (基本上,在每行上包含几个缩略图,并删除行分隔符。)

当行移出屏幕时,视图将被回收,并且 UIImageView 使用的内存也可以被回收。

请注意,这需要一些额外的工作来准确了解用户按下了哪个缩略图,但这并不太难。我过去曾这样做过,并使用 tag 属性来存储数组索引。这并不理想,但它是一个足够简单的技巧。

请注意,这仅在表格仅垂直滚动时才有效。据我所知,你不能有一个水平滚动的 UITableView。

Here's a different approach:

Use a UITableView but adjust the properties so it looks like a regular scroll view. (Basically, include several thumbnails on each row, and remove the row separator.)

As rows move off the screen, the views will be recycled and the memory used by your UIImageViews can be reclaimed.

Note that this requires some extra work to know exactly which thumbnail was pressed by the user, but it's not too hard. I've done this in the past and used the tag property to store an array index. It's not ideal, but it's a simple enough hack.

Note that this only works if you're table only scrolls vertically. As far as I know, you can't have a horizontally scrolling UITableView.

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