Iphone 使用多个图像缩放UIScrollView
我有一个包含多个UIImageView的UIScrollFrame 在这种控件中支持缩放的正确方法是什么Iphone 使用多个图像缩放UIScrollView,iphone,cocoa-touch,uikit,Iphone,Cocoa Touch,Uikit,我有一个包含多个UIImageView的UIScrollFrame 在这种控件中支持缩放的正确方法是什么 “viewForZoomingInScrollView”应该返回哪个视图?苹果公司有一段非常好的示例代码,它完全是关于UIScrollView以及缩放和平铺的。查看 此代码将在WWDC2009的Scoll Views会话中讨论。不幸的是,该会话的视频无法免费获得,但您可以将其作为iPhone WWDC2009视频包的一部分购买。我最终通过在scrollview中添加scrollview来实
“viewForZoomingInScrollView”应该返回哪个视图?苹果公司有一段非常好的示例代码,它完全是关于
UIScrollView
以及缩放和平铺的。查看
此代码将在WWDC2009的Scoll Views会话中讨论。不幸的是,该会话的视频无法免费获得,但您可以将其作为iPhone WWDC2009视频包的一部分购买。我最终通过在scrollview中添加scrollview来实现它。
这样,内部视图处理页面滑动,而外部视图处理缩放。只需将滚动视图放在另一个视图中即可 就像这样:
-(void)zoomToSelectedImage:(NSIndexPath *)indexPath
{
int currentPage = indexPath.row;
//The External Scrollview. It move back and forward
UIScrollView *contentViewZoom = [[UIScrollView alloc] initWithFrame:self.frame];
[contentViewZoom setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.8]];
[contentViewZoom setContentSize:CGSizeMake(contentViewZoom.frame.size.width * [arrayOfImages count], contentViewZoom.frame.size.height)];
[contentViewZoom setPagingEnabled:YES];
[contentViewZoom setDelegate:self];
for (int i = 0; i < [arrayOfImages count]; i++) {
CGRect frame;
frame.origin.x = contentViewZoom.frame.size.width * i;
frame.origin.y = 0;
frame.size = contentViewZoom.frame.size;
//The Internal Scrollview. It allow you zoom the picture
UIScrollView *imageScrollView = [[UIScrollView alloc]initWithFrame:frame];
[imageScrollView setTag:1];
[imageScrollView setMinimumZoomScale:1.0];
[imageScrollView setMaximumZoomScale:3.0];
[imageScrollView setAlpha:1];
[imageScrollView setDelegate:self];
[imageScrollView setBouncesZoom:YES];
[imageScrollView setClipsToBounds:YES];
[imageScrollView setShowsHorizontalScrollIndicator:NO];
[imageScrollView setShowsVerticalScrollIndicator:NO];
[imageScrollView setContentSize:CGSizeMake(768, 1024)];
UIImage *image = [arrayOfImages objectAtIndex:i];
UIImageView* imgView = [[UIImageView alloc] init];
[imgView setImage:image];
[imgView setFrame:CGRectMake(0, 0, 768, 1024)];
imgView.bounds = self.bounds;
[imgView setClipsToBounds:YES];
[imgView setContentMode:UIViewContentModeScaleAspectFit];
[imgView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[imageScrollView addSubview:imgView];
[contentViewZoom addSubview:imageScrollView];
}
[self addSubview:contentViewZoom];
[contentViewZoom setAlpha:0.2];
//Positioning according to current position
CGRect frame;
frame.origin.x = contentViewZoom.frame.size.width * currentPage;
frame.origin.y = 0;
frame.size = contentViewZoom.frame.size;
[contentViewZoom scrollRectToVisible:frame animated:NO];
}
-(void)ZoomToSelecteImage:(NSIndexPath*)indexPath
{
int currentPage=indexPath.row;
//外部滚动视图。它可以前后移动
UIScrollView*contentViewZoom=[[UIScrollView alloc]initWithFrame:self.frame];
[contentViewZoom setBackgroundColor:[UIColor-WithWhite:0.0 alpha:0.8];
[contentViewZoom设置ContentSize:CGSizeMake(contentViewZoom.frame.size.width*[arrayOfImages count],contentViewZoom.frame.size.height)];
[contentViewZoom SetPaginEnabled:是];
[contentViewZoom setDelegate:self];
对于(int i=0;i<[arrayOfImages count];i++){
CGRect帧;
frame.origin.x=contentViewZoom.frame.size.width*i;
frame.origin.y=0;
frame.size=contentViewZoom.frame.size;
//内部滚动视图。它允许您缩放图片
UIScrollView*imageScrollView=[[UIScrollView alloc]initWithFrame:frame];
[imageScrollView设置标签:1];
[imageScrollView设置最小缩放比例:1.0];
[imageScrollView设置最大缩放比例:3.0];
[imageScrollView设置Alpha:1];
[imageScrollView setDelegate:self];
[imageScrollView setBouncesZoom:是];
[imageScrollView setClipsToBounds:是];
[imageScrollView设置ShowShorizontalScrollIndicator:否];
[图像滚动视图设置显示垂直滚动指示器:否];
[imageScrollView setContentSize:CGSizeMake(7681024)];
UIImage*image=[arrayOfImages对象索引:i];
UIImageView*imgView=[[UIImageView alloc]init];
[imgView设置图像:图像];
[imgView设置帧:CGRectMake(0,07681024)];
imgView.bounds=self.bounds;
[imgView setClipsToBounds:是];
[imgView setContentMode:UIViewContentModeScaleAspectFit];
[imgView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[imageScrollView添加子视图:imgView];
[内容视图缩放添加子视图:图像滚动视图];
}
[自添加子视图:contentViewZoom];
[contentViewZoom setAlpha:0.2];
//根据当前位置定位
CGRect帧;
frame.origin.x=contentViewZoom.frame.size.width*currentPage;
frame.origin.y=0;
frame.size=contentViewZoom.frame.size;
[contentViewZoom scrollRectToVisible:帧动画:否];
}
备注:在我的情况下,屏幕大小是固定的(768x1024),您应该根据需要进行更改。Thank-我们将查看一下。之前错过了它,因为这是文档中唯一一个下载不起作用的示例。。。