iPhone iOS如何在启用缩放时使UIScrollView与UIRotationGestureRecognizer一起使用?

时间:2012-03-22 04:09:31

标签: iphone ios uiscrollview gesture uipinchgesturerecognizer

我在iOS5中工作,显然我应该能够使用scrollView.pinchGestureRecognizer控制或至少控制UIScrollView的内部捏手势识别器。

但是,我的代码似乎不起作用。识别器不会将我的类视为委托,也不会等待我的旋转手势识别器失败。我该怎么做才能使旋转手势成为优先事项,之后会考虑捏合?

更确切地说,我正在运行的问题是同时旋转和缩放的视图“从屏幕上飞向”左下角,永远不会再被看到。

-(void)setup scrollViews
{
        [tempScrollView.pinchGestureRecognizer requireGestureRecognizerToFail:rotationRecognizer];
        tempScrollView.pinchGestureRecognizer.delegate = self;

        tempScrollView.maximumZoomScale = 4.0;
        tempScrollView.minimumZoomScale = 0.25;
//        
        tempScrollView.delegate = self;
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{

    if([gestureRecognizer isEqual:rotationRecognizer])
    {
       NSLog(@"Rotation gesture");
    }else {
        NSLog(@"Other gesture: %@", [gestureRecognizer class]);
    }
    return YES;

}

    - (IBAction)rotateView:(id)sender {

        if([sender isKindOfClass:[UIRotationGestureRecognizer class]])
        {
            UIRotationGestureRecognizer* recognizer = sender;

            float recognizerRotation = [recognizer rotation];
            CGAffineTransform transform = CGAffineTransformMakeRotation(recognizerRotation);
    activeView.transform = transform;

        }

    }

1 个答案:

答案 0 :(得分:0)

据我所知,pinchGestureRecognizer中的UIScrollView是只读的。 但是,您可以尝试创建UIScrollView的子类并覆盖方法addGestureRecognizer:以禁用pinchGestureRecognizer,然后添加您自己的自定义pinchGestureRecognizer