gpt4 book ai didi

iphone - 在 UIScrollView 中添加 10 个不同的 UIImage

转载 作者:太空狗 更新时间:2023-10-30 04:00:32 25 4
gpt4 key购买 nike

我正在尝试在 UIImageView 下添加各种 UIImages 并允许它们使用 UIScrollView 滚动。我不确定如何在 UIImageView 下添加各种图像并让它们滚动。下面是我的代码,它在 UIImageView 上添加了一个图像并使其可滚动。

- (void)viewDidLoad {

[super viewDidLoad];
UIImage *image = [UIImage imageNamed:@"ae.jpg"];
imageView = [[UIImageView alloc]initWithImage:image];
imageView.frame = [[UIScreen mainScreen] bounds];
imageView.contentMode = (UIViewContentModeScaleAspectFit);
imageView.autoresizingMask = ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
imageView.backgroundColor = [UIColor clearColor];



UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
scrollView.contentMode = (UIViewContentModeScaleAspectFit);

scrollView.contentSize = CGSizeMake(image.size.width,960);
scrollView.pagingEnabled = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.alwaysBounceVertical = NO;
scrollView.alwaysBounceHorizontal = NO;
scrollView.autoresizingMask = ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
scrollView.maximumZoomScale = 2.5;
scrollView.minimumZoomScale = 1;
scrollView.clipsToBounds = YES;
[scrollView addSubview:imageView];
[image release];
[imageView release];
[self.view addSubview:scrollView];
}

最佳答案

这个想法基本上很简单。假设您要在 UIScrollView 中放置 3 个图像。每张图片都是 300x300。在这种情况下,您将拥有带框架的 ScrollView :

scrollView.contentSize = CGSizeMake(image.size.width,900);

对于每张图片,您都必须拥有具有适当框架的 UIImageView:

imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0, 300, 300)];
imgView2 = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 300, 300, 300)];
imgView3 = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 600, 300, 300)];
imgView1.image = [UIImage imageNamed:@"ProperName.png"];
...

(注意 yOrigin(CGRectMake 中的第二个值))然后像你一样:

[scrollView addSubview:imgView1];
[scrollView addSubview:imgView2];
[scrollView addSubview:imgView3];
[imgView1 release];
[imgView2 release];
[imgView3 release];

当然,这是一个简短的代码,你会优化它;)

关于iphone - 在 UIScrollView 中添加 10 个不同的 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6876089/

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