iOS:仅通过多点触控缩放 uiscrollview

发布于 2025-01-04 17:49:06 字数 1214 浏览 1 评论 0原文

我有这样的代码:

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

如你所见,我想缩放滚动视图,其中包含图像;当我用手指触摸滚动视图时,我对图像进行着色,而当我用两根手指触摸滚动视图时,我想对其进行缩放,并且如果我用手指触摸,则必须禁用缩放。 使用我的代码不会发生这种情况;它可以识别双击,但不能主动缩放,为什么?

I have this code:

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

as you can see, I want to zoom scrollView with an image inside; when I touch scrollView with a finger I color image, instead when I touch with two fingers scrollview, I want to do a zoom on it, and after if I touch with a finger zomm must be disabled.
with my code it don't happen; it recognize double touch but don't active zoom, why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太阳男子 2025-01-11 17:49:06

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

UIScrollView 类可以有一个必须采用 UIScrollViewDelegate 协议的委托。为了使缩放和平移工作,委托必须同时实现 viewForZoomingInScrollView: 和scrollViewDidEndZooming:withView:atScale:;另外,最大(maximumZoomScale)和最小(minimumZoomScale)缩放比例必须不同。

希望有帮助。

UIScrollView 类参考

I think the problem is that you are not implementing all required delegate methods for zooming.

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.

Hope it helps.

UIScrollView Class Reference

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文