gpt4 book ai didi

ios - 我应该如何在 PinchGestureRecognizer 上保持缩放比例?

转载 作者:行者123 更新时间:2023-11-30 17:11:13 25 4
gpt4 key购买 nike

我想通过PinchGestureRecognizer实现缩放功能。我可以通过这段代码进行缩放,但是只要我张开手指,imageView就会恢复。我想做一个功能,如果我有时缩放 imageView,它不会每次都恢复。并且代码 scrollView.minimumZoomScale = 3.0scrollView.maximumZoomScale = 6.0 不起作用。

我应该做什么?

这是我的代码

        scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
scrollView.frame = self.view.bounds;
scrollView.backgroundColor = [UIColor blueColor];
scrollView.contentSize = CGSizeMake(imgView.bounds.size.width+100, imgView.bounds.size.height);
scrollView.frame = CGRectMake(0,50,320,500);
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
scrollView.pagingEnabled = YES;
scrollView.bouncesZoom = YES;
scrollView.minimumZoomScale = 3.0;
scrollView.maximumZoomScale = 6.0;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
[self.view addSubview:scrollView];

UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc]
initWithTarget:self action:@selector(handlePinchGesture:)];
[scrollView addGestureRecognizer:pinchGesture];

img =[UIImage imageNamed:[NSString stringWithFormat:@"a.jpg"]];
imgView = [[UIImageView alloc]initWithImage:img];
imgView.frame = CGRectMake(0,0, self.view.frame.size.width, 448);
imgView.userInteractionEnabled = YES;
[scrollView imgView];


- (void)handlePinchGesture:(UIPinchGestureRecognizer *)sender {
CGFloat factor = [(UIPinchGestureRecognizer *)sender scale];
imgView.transform = CGAffineTransformMakeScale(factor, factor);
NSLog(@"factor %f",factor);

}

最佳答案

尝试使用CGAffineTransformScale代替:

imgView.transform = CGAffineTransformScale(imgView.transform, factor, factor);

关于ios - 我应该如何在 PinchGestureRecognizer 上保持缩放比例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32432364/

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