带分页的 4 个方向滚动视图

发布于 2024-11-09 12:47:03 字数 266 浏览 0 评论 0原文

我需要实现一个滚动视图(按下按钮时)将根据按下的按钮向上、向左、向下或向右翻页。用户还可以无限期地朝同一方向翻页,这将在一种轮播中加载视图。所以我有3个viewController....首先显示viewController 1....用户按下左键,它显示viewController2,左键再次显示viewController3,左键再次返回viewController 1等,上、下、右也是如此。

有谁知道实现这个的好方法?我对所有建议持开放态度。

非常感谢

朱尔斯

I need to implement a scroll view which (on a button press) will page either up, left, down or right depending on which button was pressed. Also the user can indefinately page in the same direction which will load the views in a kind of carousel. So I have 3 viewControllers.... viewController 1 is shown first....The user presses left, it shows viewController2, left again shows viewController3, left again is back to viewController 1 etc. and the same for up,down,right.

Does anyone know a good way to implement this? Im open to all suggestions.

Many thanks

Jules

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

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

发布评论

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

评论(1

书信已泛黄 2024-11-16 12:47:03

编辑-第二次尝试明确解释:

考虑这个矩阵。

在此处输入图像描述

  • 这个 3x4 矩阵是滚动视图的内容区域。启用分页后,您的滚动视图将停止在这些“单元格”之一上,例如 2,1。滚动视图的该部分将可见。
  • 如果您希望每个“单元格”由它自己的视图控制器控制,则预先生成所有视图控制器(及其视图),然后将它们的所有视图作为子视图添加到滚动视图中。
  • 您可以使用您想要在任何给定位置显示的任何视图来填充此滚动视图。设置每个视图相对于滚动视图原点的框架。因此,如果单元格宽度为 320 像素,高度为 480 像素,则单元格 1,3 的框架将为 CGRectMake(1*320, 3*480, 320,480)。
  • 当scrollView结束减速时,您可以获取它的contentOffset属性,进行一些算术并找出您所在的单元格。
  • 为了获得环绕效果,您必须做一些技巧。您可以在每行和每列的末尾放置一个额外的单元格,如果您发现自己位于该单元格中,只需将滚动视图的 contentOffset 设置为行或列开头的相应单元格即可。

Edit - second attempt at a clear explanation:

Consider this matrix.

enter image description here

  • This 3x4 matrix is the content area of your scroll view. With paging enabled, your scroll view will stop on one of these "cells", e.g. 2,1. That portion of the scroll view will be visible.
  • If you want each "cell" to be controlled by it's own view controller, then pre-generate all the view controllers (and their views), and then add all of their views as subviews to the scrollView.
  • You would populate this scroll view with whatever view you wanted to show at any given location. Set the frame of each view relative to the scrollview's origin. So if the cells were 320 pixels wide and 480 pixels tall, the frame for cell 1,3 would be CGRectMake(1*320, 3*480, 320,480).
  • When the scrollView ends deceleration, you can get it's contentOffset property, do some arithmetic and figure out which cell you're in.
  • To get the wrap-around effect, you'll have to do some trickery. You might put an extra cell at the end of each row and column, and if you find yourself in that cell, just set the scrollviews' contentOffset to the corresponding cell at the beginning of the row or column.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文