无尽的 iPad 滑动?

发布于 2024-08-30 08:57:33 字数 124 浏览 2 评论 0原文

我想实现一个 ipad 视图,在其中解析 xml 文件并将条目并排放置在“无尽”的 ipad 视图上,因此您必须向左和向右滑动它。有人可以告诉我如何实现这个吗?我必须使用哪种类型的视图?

预先感谢

问候

i want to implement a ipad view, where i parse an xml file and put the entries side by side on an "endless" ipad view, so you have to swipe through it left and right. could someone tell me how i can implement this? which type of view do i have to use?

thanks in advance

regards

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

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

发布评论

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

评论(2

他是夢罘是命 2024-09-06 08:57:33

使用非常大的 contentSize 并不是正确的方法。 contentSize 仍然使用固定的数据类型,如果你滚动足够长的时间,它们就会溢出,最多你的绘图会变得混乱。最坏的情况是,您的应用程序崩溃。

您想要的是通过使用窗口给人无限滚动的印象。我将通过一个简单的一维示例来说明它是如何工作的,但您可以轻松地将其扩展到二维。

假设您有 3 个条目,其中每个条目都填充 UIScrollView。向右滚动,它看起来会像这样排列:

A B C A B C A B C ...

在内部,您将像这样排列它们:

C A B C

因为当 A 可见时,如果向右滑动,您可以看到 C 的一部分,如果向右滑动,您可以看到 B 的一部分向左滑动。

您的 UIScrollViewcontentOffset 是您的窗口。虽然 contentSize 包含所有四个实体 (CAB C) 的宽度,但在内部您将其限制为实际宽度的 75%。当用户左右滚动时,您可以调整 contentOffset,使其永远不会为负数或超过 contentSize.width 的 75%。这是在您的委托内部完成的,在 scrollViewDidScroll: 中,

- (void) scrollViewDidScroll:(UIScrollView *)scrollView
{
    while (scrollView.contentOffset.x < 0)
        scrollView.contentOffset.x += constrainedContentSize.width;
    while (scrollView.contentOffset.x > constrainedContentSize.width)
        scrollView.contentOffset.x -= constrainedContentSize.width;

    // ...
}

请注意,这假设有一个实例变量 constrainedContentSize,可能在您的 UIScrollView 视图的控制器中。位于内部,并且控制器是您的 UIScrollView 委托。

这比不断释放和重新创建视图要高效得多。

Using a really big contentSize isn't the way to go. contentSize still uses fixed datatypes, and if you scroll long enough, they'll overflow and at best, your drawing will go haywire. Worst case, your app crashes.

What you want is to give the impression of infinite scrolling by using a window. I'll illustrate how it works with a simple 1-D example, but you can easily extend it to 2-D.

Let's say you have 3 entries, where each one fills the UIScrollView. Scrolling to the right, it would appear to be arranged like this:

A B C A B C A B C ...

Internally, you're going to arrange them like this:

C A B C

Because when A is visible, you can see part of C if you swipe to the right or part of B if you swipe to the left.

Your UIScrollView's contentOffset is your window. While contentSize encompasses the width of all four entities (C A B C), internally you're going to restrict that to 75% of the actual width. As your user scrolls left and right, you adjust contentOffset so that it is never negative or more than 75% of contentSize.width. This is done inside your delegate, in scrollViewDidScroll:

- (void) scrollViewDidScroll:(UIScrollView *)scrollView
{
    while (scrollView.contentOffset.x < 0)
        scrollView.contentOffset.x += constrainedContentSize.width;
    while (scrollView.contentOffset.x > constrainedContentSize.width)
        scrollView.contentOffset.x -= constrainedContentSize.width;

    // ...
}

Note that this assumes an instance variable constrainedContentSize, likely in the controller for the view that your UIScrollView is inside, and that the controller is your UIScrollView delegate.

This will be far more efficient than constantly releasing and recreating views.

放低过去 2024-09-06 08:57:33

您使用启用分页的 UIScrollView。要点是将 myscrollView.contentSize 设置为所有页面的总宽度,但在滚动发生时及时创建各个页面(请参阅 UIScrollViewDelegate 文档);换句话说,当您需要的只是三个视图(当前视图以及上一个视图和下一个视图)时,您实际上不希望有数十个或更多视图耗尽内存。苹果的这个示例代码应该可以帮助您入门:
http://developer.apple.com/iphone/library/示例代码/滚动/简介/Intro.html

You use UIScrollView with paging enabled. The essentials will be setting myscrollView.contentSize to the total width of all your pages, but creating the individual pages on a just-in-time basis as the scrolling is happening (see the UIScrollViewDelegate documentation); in other words you don't want to actually have dozens or more views using up memory when all you need is three -- the current view and plus the previous and next views. This sample code from apple should get you started:
http://developer.apple.com/iphone/library/samplecode/Scrolling/Introduction/Intro.html

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