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

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

问题描述

我是否真的需要在UIScrollView中使用UIPinchGestureRecognizer才能使捏合工作?如果是,我该怎么办?我正在尝试实现flipboard所具有的功能,它基本上放大图像并在放大后具有滚动功能。我该怎么做?

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?

UPDATE :

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

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];


推荐答案

您需要做的就是添加<$ c在$ code> UIScrollView 中的$ c> 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天全站免登陆