使用 UIImage 放大滚动视图 [英] Zoom in Scroll view with UIImage
本文介绍了使用 UIImage 放大滚动视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图放大带有多个图像的滚动视图,滚动视图仅垂直滚动,我尝试实现多种方式,在许多示例中,但没有一个可以工作.下面是我用来创建图像和滚动视图的代码:
Im trying to zoom in a scroll view with multiple images, the scroll view only scrolls vertical, i tried to implement many ways, in many examples but none seens to work. Heres the code im using to create the images and the scroll view:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
for (int i = 0; i < 6; i++)
{
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"amap1%i.png",i+1]];
// create imageView
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, _scrollView.frame.size.height*i, _scrollView.frame.size.width, _scrollView.frame.size.height)];
// set scale to fill
_imageView.contentMode = UIViewContentModeScaleToFill;
// set image
[_imageView setImage:image];
// add to scrollView
[self.scrollView addSubview:_imageView];
}
_scrollView.contentSize = CGSizeMake(_scrollView.frame.size.width, _scrollView.frame.size.height * 6);
_scrollView.bounces = NO;
_scrollView.pagingEnabled = YES;
}
推荐答案
看起来您需要使用 UIScrollView 为每个图像(以放大)执行 UIScrollView(以包含所有图像 - 水平滚动).
Looks like you'll need to do a UIScrollView (to contain all the images - horizontal scrolling) with a UIScrollView for each image (to zoom in).
有一个 WWDC 视频讨论了如何做到这一点(WWDC 2010 - Session 104;iTunes 链接)
There's a WWDC video which talks about how to do this (WWDC 2010 - Session 104; link to iTunes)
这篇关于使用 UIImage 放大滚动视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文