iphone - UIImageView 和 UIScrollView 缩放

标签 iphone objective-c ios ipad uiscrollview

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

更新:

这是我的一些不调用 ScrollView 委托(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];

最佳答案

您需要做的就是将您的 UIImageView(或任何您想要缩放的 View )添加到您的 UIScrollView 中。

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

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

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

关于iphone - UIImageView 和 UIScrollView 缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8891356/

相关文章:

iphone - iOS静态库的向后兼容性

iphone - 键盘出现后 UISCcrollView 的 contentSize 发生变化

ios - 无法将 NSString 从一个 VC 传递到下一个 VC

ios - 您可以在 Xcode 的实用程序面板中添加自定义按钮吗?

ios - UITextField 可以自动打开语音输入吗?

iphone - Facebook iOS SDK - 向 Facebook 用户发送应用程序请求

objective-c - 弹出时 UIViewController 未被释放

objective-c - 关于NSNumber numberWithDouble

ios - 从 Objective-C 迁移到 Swift : AFNetworking > Alamofire

ios - 为什么我的 UILabel 没有在 queryPedometerDataFromDate 内更改?