开发者

4 directional scrollview with paging

开发者 https://www.devze.com 2023-03-08 18:42 出处:网络
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 sa

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


Edit - second attempt at a clear explanation:

Consider this matrix.

4 directional scrollview with paging

  • 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.
0

精彩评论

暂无评论...
验证码 换一张
取 消