如何在ios中缩小缩放的图像



我有这样的代码。

在加载视图()

我已经创建了这样的滚动视图,没有点击和最大值

self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
self.scrollView.delegate = self;
self.scrollView.maximumZoomScale = 2;
self.scrollView.autoresizingMask = self.view.autoresizingMask;
[self.view addSubview:self.scrollView];
UITapGestureRecognizer *tapOnce = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
[tapOnce setNumberOfTouchesRequired:1];
[doubleTap setNumberOfTapsRequired:2];
[tapOnce requireGestureRecognizerToFail:doubleTap];
[self.scrollView addGestureRecognizer:tapOnce];
[self.scrollView addGestureRecognizer:doubleTap];

方法实现:

- (void) handleSingleTap:(UIGestureRecognizer *)gestureRecognizer
{
//single tap in full screen mode it will dismiss the view
  [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer 
{
//double tap will zoom the view to scrollview max value
  [self.scrollView setZoomScale:self.scrollView.maximumZoomScale animated:NO];   
}

现在我可以在点击全屏图像时"缩放",它将进入 maxZoom 值,但如何在双击时从缩放到最小值返回相同,因为我具有在单击时关闭视图的功能。我需要在"handledoubleTap"方法本身中再处理一次双击。

- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer 
{
    if ( flag == 1 ){
        flag = 0;
        [self.scrollView setZoomScale:self.scrollView.maximumZoomScale animated:NO];   
    }
    else {
        flag = 1;
        [self.scrollView setZoomScale:self.scrollView.minimumZoomScale animated:NO];   
    }
}

在上面的方法中,只需根据您的需要设置标志即可。希望这有帮助..:)

最新更新