UIScrollView and image thumbnails
I want to have a scroll view, where you display 5 thumbnails on the scroll view each time. Basically it's a table with one row and in each row we have 5 thumbnails in it. You slide your finger to the right then you display the next set of 5 thumbnails.
开发者_StackOverflow社区What do I need to do this?? Is it true that we need a scroll view to do this? How can I start?
In your UIView that will contain your UIScrollView, place (something like) this code in -viewDidLoad:
UIScreen *screen = [UIScreen mainScreen];
pageWidth = screen.bounds.size.height;
pageHeight = screen.bounds.size.width;
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, pageWidth, pageHeight)];
[scrollView setAutoresizingMask:UIViewAutoresizingNone];
[scrollView setContentSize:CGSizeMake(numPages * pageWidth, pageHeight)];
[scrollView setContentOffset:CGPointMake(pageWidth, 0)];
[scrollView setPagingEnabled:YES];
[scrollView setDelaysContentTouches:YES];
[scrollView setDelegate:self];
[scrollView setClearsContextBeforeDrawing:NO];
[scrollView setOpaque:YES];
[self.view insertSubview:scrollView atIndex:0];
[scrollView release];
// iterate through your thumbnails - which are UIViews
thumbnailViews = [NSMutableArray array];
[thumbnailViews retain];
NSUInteger pageCounter = 0;
for (...)
{
ThumbnailView *thumbnailView = [[ThumbnailView alloc] initWithFrame:CGRectMake( pageCounter*pageWidth, 0, pageWidth, pageHeight )];
[thumbnailView setMultipleTouchEnabled:YES];
[thumbnailView setViewController:self]; // this may be necessary to push/pop on navigation controller stack.
[thumbnailView restoreState];
[scrollView thumbnailView];
[thumbnailViews thumbnailView];
++pageCounter;
}
In my case, pageWidth, pageHeight, thumbnailViews and scrollView are all ivars for my UIView subclass.
I just looked in here as I'm learning about UIScrollView
s myself. I started to try and get westsider's code to work, but I noticed that it is practically gobblygook. It should be in a UIViewController
that implements the <UIScrollViewDelegate>
protocol, and things like [scrollView thumbnailView];
is meaningless as here thumbnailView
is a method name. I believe http://www.codeproject.com/Articles/46556/How-To-Use-UIScrollView-in-Your-iPhone-App.aspx is more coherent.
To answer the question, I think you want to create a UIScrollView
in a standard manner--such as in the link, and you want to create a subclass of UIView
called, say, UIView5
that has 5 UIImageViews
. Then, instead of adding a normal UIView
to the UIScrollView
, like [scrollView addSubview:standardUIView];
, you add UIView5
objects.
精彩评论