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

时间:2015-01-07 04:15:13

标签: ios objective-c uiscrollview

我有这样的代码..

在loadView()

我创建了这样的滚动视图,其中包含no.of tap和max value

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值,但是如何在双击时从缩放到最小值,因为我有功能可以关闭视图单击。我需要在“processedoubleTap”方法中再处理一次双击。

1 个答案:

答案 0 :(得分:0)

- (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];   
    }

}

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