iOS-使用scrollViewDidZoom和touchesMoved

时间:2019-03-08 06:56:29

标签: ios objective-c

我正在添加两个手指手势来平移UIScrollView中的自定义3D视图。内部工作不是我做的,仅仅是点的计算以及如何将其绘制到3D视图中。我主要关心的是scrollViewDidZoomtouchesMoved函数与我尝试过的方法相冲突。

我尝试计算touches函数的touchesMoved,但是它不是很稳定。

我尝试添加UIPanGestureRecognizer,但与scrollViewDidZoom冲突。另外,由于我使用的是自定义变量,因此minimumNumberOfTouchesmaximumNumberOfTouches属性无法正常工作。

我想知道如何添加不会与视图中现有手势冲突的两指手势。

这是用Obj-c编写的,因此是标签,但是欢迎使用Swift回答。

这是代码的摘录。它并没有显示太多,但是基本上我想更好地控制panMode bool。

- (UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView {
    return zoomDummyView;
}

- (void)scrollViewDidZoom:(UIScrollView*)scrollView {

    if ([scrollView zoomScale] != 3.0f)
    {
        //do calculation on zooming
    }
}

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

    [super touchesBegan:touches withEvent:event];

    NSArray* array = [touches allObjects];

    //this is what I've tried so far - check count of touches and then use the bool to denote pan mode or not

    panMode = array.count > 1 ? true : false

    for ( int i = 0; i < [array count]; ++i )
    {
        //do point calculation    
    }
}

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

    [super touchesMoved:touches withEvent:event];


    NSArray* array = [touches allObjects];
    for ( int i = 0; i < [array count]; ++i )
    {
        //some point calculation

    // simulation of mouse control for the 3D view, as you can see panMode is used to indicate movement between tilt and pan.

        input.isLeftButtonDown = !panMode; // for tilt mode
        input.isRightButtonDown = false;
        input.isMiddleButtonDown = panMode; // for pan mode
        input.isSideButton1Down = false;
        input.isSideButton2Down = false;

        //input simulation
    }
}

0 个答案:

没有答案