Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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!

like image 628
devunwired Avatar asked Apr 23 '10 22:04

devunwired


2 Answers

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.

like image 118
mbmcavoy Avatar answered Nov 13 '22 12:11

mbmcavoy


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)

like image 42
Ameer Sheikh Avatar answered Nov 13 '22 10:11

Ameer Sheikh