如何将扩展限制为默认视图大小

时间:2012-06-04 14:56:37

标签: iphone uipinchgesturerecognizer

我正在研究基于pdf的应用程序,我正在尝试实现UIPinchGestureRecognizer。我希望在用户达到640,960的默认视图大小时限制夹断功能。

在我目前的实现中,用户可以捏合/缩小无限。

- (void)pinchZoom:(UIPinchGestureRecognizer *)gestureRecognizer
{
    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {

        if (!zoomActive) {
            zoomActive = YES;

            UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panMove:)];
            [panGesture setMaximumNumberOfTouches:2];
            [panGesture setDelegate:self];
            [self addGestureRecognizer:panGesture];
            [panGesture release];

        }

        [gestureRecognizer view].transform = CGAffineTransformScale([[gestureRecognizer view] transform], [gestureRecognizer scale], [gestureRecognizer scale]);

        [delegate leavesView:self zoomingCurrentView:[gestureRecognizer scale]];            

        [gestureRecognizer setScale:1];


    }
}  

    // This method will handle the PAN / MOVE gesture 
- (void)panMove:(UIPanGestureRecognizer *)gestureRecognizer    
{
    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {  
        CGPoint translation = [gestureRecognizer translationInView:[[gestureRecognizer view] superview]];  
        [[gestureRecognizer view] setCenter:CGPointMake([[gestureRecognizer view] center].x + translation.x, [[gestureRecognizer view] center].y + translation.y)];  
        [gestureRecognizer setTranslation:CGPointZero inView:[[gestureRecognizer view] superview]];   
    }  
}

这是我所说的默认视图大小/比例:default pdf

这是我不想要的,或者我想限制捏出:
infinite pinch out

有什么建议吗?

2 个答案:

答案 0 :(得分:3)

如何处理自己处理程序函数的下限?像这样:

- (void)pinchZoom:(UIPinchGestureRecognizer *)gestureRecognizer {

     ....

    if ( [gestureRecognizer scale] > MIN_SCALE )
        [gestureRecognizer view].transform = CGAffineTransformScale([[gestureRecognizer view] transform], [gestureRecognizer scale], [gestureRecognizer scale]);
  ...

答案 1 :(得分:2)

在您的gestureRecognizer内部,您将需要测试并了解PDF视图的当前比例/大小,并且在占据全屏时不要缩小。