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

Posted

技术标签:

【中文标题】IOS:仅使用多点触控缩放 uiscrollview【英文标题】:IOS: zoom for a uiscrollview only with multitouch 【发布时间】: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。 用我的代码不会发生;它可以识别双击但不主动缩放,为什么?

【问题讨论】:

【参考方案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

【讨论】:

以上是关于IOS:仅使用多点触控缩放 uiscrollview的主要内容,如果未能解决你的问题,请参考以下文章

有人可以解释多点触控缩放是不是应该适用于 UITextView 或 UIScrollView

Android实现多点触控,自由缩放图片

ActionScript 3 As3:多点触控缩放和旋转

所有子控件也随着缩放手势缩放layout多点触控layout

Android自定义ImageView实现图片缩放滑动,双击放大缩小,多点触控缩放

Android自定义ImageView实现图片缩放滑动,双击放大缩小,多点触控缩放