IOS:仅使用多点触控缩放 uiscrollview

标签 ios xcode uiscrollview zooming multi-touch

我有这个代码:

[scrollView setMinimumZoomScale:1.00];
[scrollView setMaximumZoomScale:2.00];
scrollView.delegate=self;

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

   NSSet *allTouches = [event allTouches];
    if ([allTouches count] == 2) {

        NSLog(@"multitouch");
        zoomMultiTouch = TRUE;


    }

     else if ([allTouches count] == 1){

        NSLog(@"single touch");
        zoomMultiTouch = FALSE;
    }

     else return;

}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {


    if (zoomMultiTouch){
        scrollView.userInteractionEnabled = YES;
        scrollView.scrollEnabled = YES;
        NSLog(@"zoomMultitouch moved");
    }

    else {
        scrollView.userInteractionEnabled = NO;
        scrollView.scrollEnabled = NO;
        NSLog(@"NOzoom moved");
    }

  //some code for coloring an image

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    scrollView.userInteractionEnabled = NO;
    scrollView.scrollEnabled = NO;
    zoomMultiTouch = FALSE;
}

如您所见,我想缩放带有图像的 scrollView;当我用手指触摸 scrollView 时我给图像上色,而不是当我用两个手指触摸 scrollview 时,我想对其进行缩放,如果我用手指触摸 zomm 之后必须禁用。 使用我的代码不会发生;它识别双击但不主动缩放,为什么?

最佳答案

我认为问题在于您没有实现所有必需的缩放委托(delegate)方法。

The UIScrollView class can have a delegate that must adopt the UIScrollViewDelegate protocol. For zooming and panning to work, the delegate must implement both viewForZoomingInScrollView: and scrollViewDidEndZooming:withView:atScale:; in addition, the maximum (maximumZoomScale) and minimum ( minimumZoomScale) zoom scale must be different.

希望对您有所帮助。

UIScrollView Class Reference

关于IOS:仅使用多点触控缩放 uiscrollview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9263978/

相关文章:

ios - 使用屏幕纵横比裁剪部分 UIImage

iphone - 当键盘显示时向上移动 UIView

javascript - 无法在本地 html 文件中的 webview 中加载谷歌地图

ios - 以编程方式在 Stackview 上设置间距

ios - Xcode Server CI 构建无法安装 iOS 7.1

iphone - 在方法中运行时,从 nib 加载的 View 不会更新 UILabel 的内容

ios - 使用 strokeColor,从中心到圆周绘制一条线

javascript - 如何使用cordova处理ios中下载的插件文件夹

c# - 如何从web service获取流类型的数据

ios - 一起水平滚动 UICollectionView 的所有行