gpt4 book ai didi

ios - 双击无法缩放图像

转载 作者:行者123 更新时间:2023-11-28 21:27:03 26 4
gpt4 key购买 nike

我按如下方式加载 ImageView 。 self.displayReceivedImageScrollView 是在头文件中定义的 ScrollView 属性。

   _displayImage.image = nil;


dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void) {
NSData *data0 = [NSData dataWithContentsOfURL: [NSURL URLWithString:savedValue]];
UIImage *image = [UIImage imageWithData: data0];

dispatch_sync(dispatch_get_main_queue(), ^(void) {
_displayImage.image = image;
});
});


UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];

[doubleTap setNumberOfTapsRequired:2];

[self.displayReceivedImageScrollView addGestureRecognizer:doubleTap];

以下是我的 doubleTap 处理程序。我希望在用户双击图像时缩放图像。

- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer {

if(self.displayReceivedImageScrollView.zoomScale > self.displayReceivedImageScrollView.minimumZoomScale)
[self.displayReceivedImageScrollView setZoomScale:self.displayReceivedImageScrollView.minimumZoomScale animated:YES];
else
[self.displayReceivedImageScrollView setZoomScale:self.displayReceivedImageScrollView.maximumZoomScale animated:YES];

}

但问题是,图像没有被缩放。 handleDoubleTap 方法根本没有被触发,为什么会这样?

最佳答案

您可以通过将 View 放入 ScrollView 和配置来启用缩放:

@property(nonatomic) CGFloat minimumZoomScale;     // default is 1.0
@property(nonatomic) CGFloat maximumZoomScale; // default is 1.0. must be > minimum zoom scale to enable zooming

关于ios - 双击无法缩放图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37672178/

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