【发布时间】:2011-07-29 16:21:44
【问题描述】:
我正在尝试在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 中使用多个 UIImageView。但目前还不清楚你想要它做什么。
-
我想在一张下方添加各种图像,例如想要在“ae.png”下方添加另一张图像并允许它滚动。可以说目前它只有一个图像,但是如果我想在 UIIImageView 中添加一组图像,可以吗?
-
只使用多个 UIImageViews。
-
好的。但是,您将如何以编程方式确定图像的位置?
标签: iphone objective-c uiscrollview uiimageview uiimage