UIImageView 和 UIScrollView 缩放 [英] UIImageView and UIScrollView zooming

查看:30
本文介绍了UIImageView 和 UIScrollView 缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的需要在 UIScrollView 中使用 UIPinchGestureRecognizer 才能使捏合工作吗?如果是,我该怎么做?我正在尝试实现翻转板的功能,它基本上可以放大图像并在放大后具有滚动功能.我该怎么做?

Do I actually need a UIPinchGestureRecognizer inside a UIScrollView to have the pinch working? If yes how do I do it? I am trying to implement what flipboard has, where it basically zooms in an image and have the scroll capability after zooming in. How do I do that?

更新:

这是我没有调用滚动视图委托的一些代码

Here's some code that I have which doesn't call the scroll view delegate

CGRect imgFrame;
imgFrame.size.width = originalImageSize.width;
imgFrame.size.height = originalImageSize.height;
imgFrame.origin.x = imageOriginPoint.x;
imgFrame.origin.y = imageOriginPoint.y;

NSData *data = [request responseData];
UIImage * image = [UIImage imageWithData:data];
imageView = [[UIImageView alloc] initWithImage:image];
[imageView setUserInteractionEnabled:YES];
[imageView setBackgroundColor:[UIColor clearColor]];
[imageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[imageView setFrame:CGRectMake(0, 0, imgFrame.size.width, imgFrame.size.height)];

UIScrollView * imgScrollView = [[UIScrollView alloc] initWithFrame:imageView.frame];
imgScrollView.delegate = self;
imgScrollView.showsVerticalScrollIndicator = NO;
imgScrollView.showsHorizontalScrollIndicator = NO;
[imgScrollView setScrollEnabled:YES];
[imgScrollView setClipsToBounds:YES];
[imgScrollView addSubview:imageView];
[imgScrollView setBackgroundColor:[UIColor blueColor]];
[imgScrollView setMaximumZoomScale:1.0];

推荐答案

所有你需要做的就是在你的 UIScrollView 中添加你的 UIImageView(或任何你想要缩放的视图)代码>.

All you need to do is add your UIImageView (or any view you want to zoom) inside your UIScrollView.

UIScrollView 上的 maximumZoomScale 设置为高于 1.0f 的任何值.

Set your maximumZoomScale on your UIScrollView to any value higher than 1.0f.

将自己设置为 UIScrollView 的委托,并在 viewForZooming 委托方法中返回 UIImageView.

Set yourself as the delegate of your UIScrollView and return the UIImageView in the viewForZooming delegate method.

就是这样.不需要捏手势,什么都不需要.UIScrollView 为您处理捏合缩放.

That's it. No pinch gesture needed, no nothing. UIScrollView handles pinch zooming for you.

这篇关于UIImageView 和 UIScrollView 缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆