【问题标题】:IOS: zoom for a uiscrollview only with multitouchIOS:仅使用多点触控缩放 uiscrollview
【发布时间】:2012-02-13 16:21:13
【问题描述】:

我有这个代码:

[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;
}

如您所见,我想用里面的图像缩放滚动视图;当我用手指触摸滚动视图时,我会为图像着色,而不是当我用两根手指触摸滚动视图时,我想对其进行缩放,如果我用手指触摸,则必须禁用 zomm。 用我的代码不会发生;它可以识别双击但不主动缩放,为什么?

【问题讨论】:

    标签: ios xcode uiscrollview zooming multi-touch


    【解决方案1】:

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

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-13
      • 2011-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多