开发者

iPhone Horizontal Scrolling Table

I need to create a view on the iPhone that scrolls horizontally through a gallery of images. The issue is that this gallery has the potential to have 100s to 1000s of images that needs to be presented, so I would like to avoid loading 开发者_JAVA技巧them all into a single UIScrollView at once and destroying performance. I need to create a view that recycles the view objects (like UITableView) to increase performance and reduce memory overhead, but it needs to scroll in a horizontal fashion.

Any ideas? Is it possible to make UITableView operation horizontally?

Thanks!


You could use a large scrollview, and monitor for the scroll position to change. You can add images as subviews as they are coming into the actual viewable area, and remove them as they are scrolled away.

This way, you only have to have a small number of image views present at any given time, but you give the appearance of them all being "there".

You could even recycle the image views by changing their image and location so you are not creating and destroying complex objects. This is what UITableView does with cells.


It is as simple as appyling a Transform.

Here is the code. Write this in the your tableViewController init:

self.view.frame = CGRectMake(100,-5,250,350); //any Frame of your choice
CGAffineTransform trans = self.view.transform; // get current transform (i.e. portrait)
trans = CGAffineTransformRotate(trans, (M_PI / -2.0)); // rotate 90 degrees to go landscape
self.view.transform = trans; // set current transform (landscape)

But now what you need to realize is that your axis are also swapped. Any changes you make to the height will change the width (and vice versa) and any changes made to the origin.x changes the origin.y (and vice versa)


I agree with mbmcavoy, you can also take a look iPhone/iPad – AppStore like UIScrollView with paging and preview this article explains what you need about UIScrollView as well as provides a good example and source code.

Regards


Is it possible to add a UITableView horizontally? In a different orientation than the screen. Then you can use regular UITableView semantics where each row is an image that scrolls horizontally instead of vertically.


Posting an answer to this old thread because the validated answer is not correct. You may use a UITableViewController and its dequeueReusableCellWithIdentifier built-in features.

The trick is to make your tableview rotate and then make your cell rotate in the opposite direction.

in viewDidLoad you will add:

self.view.transform = CGAffineTransformMakeRotation(-M_PI_2);

And then in cellForRowAtIndexPath you would use:

cell.containerView.transform = CGAffineTransformMakeRotation(M_PI_2);

Make sure that every content of your cell is added to a container view (in this example containerView) so that you only have to rotate the container and not every cell subview.

Also please note that it will work better with cells having square dimensions, cause otherwise you may struggle with height/width computation.


I think I have the answer for you About scrolling an UITableView Horizontally:

  1. create an UIScrollView (and disable the vertical scroll)
  2. put an UITableView inside the scroll view
  3. change the table view width as you wish and update the UIScrollView.contentSize as the tableView width
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜