gpt4 book ai didi

iphone - UIScrollView 和图像缩略图

转载 作者:行者123 更新时间:2023-12-03 21:21:32 24 4
gpt4 key购买 nike

我想要一个 ScrollView ,每次在 ScrollView 上显示 5 个缩略图。基本上它是一个只有一行的表格,每行都有 5 个缩略图。您向右滑动手指,然后显示下一组 5 个缩略图。

我需要做什么?我们真的需要一个 ScrollView 来做到这一点吗?我该如何开始?

最佳答案

在包含 UIScrollView 的 UIView 中,将此代码(类似于)放置在 -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;
}

在我的例子中,pageWidth、pageHeight、thumbnailViews和scrollView都是我的UIView子类的ivars。

关于iphone - UIScrollView 和图像缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4101926/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com