gpt4 book ai didi

iphone - UIImageView 和 UIScrollView 缩放

转载 作者:IT王子 更新时间:2023-10-29 07:53:10 26 4
gpt4 key购买 nike

我真的需要在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com