0

我正在使用 UIPinchGestureRecognizer 来触发模态 UIViewController 的外观,它允许缩放和平移图像。它本质上可以让您隔离一个图像并更详细地探索它。

新的 UIViewController 有自己的捏和平移手势识别器。

我注意到的一个缺点是,一旦新的 UIViewController 出现,用户必须在新的手势识别器识别触摸事件之前将手指从屏幕上移开并再次开始捏合。

理想情况下,我希望捏合是无缝的,因此一旦模态 UIViewController 出现,用户就可以继续捏合和/或平移。有没有办法将触摸事件从前一个视图控制器转换为模态事件,从而触发新 UIViewController 中的手势识别器?

我用来触发模态缩放视图控制器的代码:

- (IBAction)zoomImage:(UIPinchGestureRecognizer *)sender
{
    // if the gesture was released while the scale factor is sufficiently big, show the modal view
    if ( sender.state == UIGestureRecognizerStateEnded && sender.scale > 1.6f ) {
        // prepare the modal view controller
        ZoomViewController *viewControllerZoom = [[ZoomViewController alloc] initWithNibName:nil bundle:nil];
        [viewControllerZoom setImage:self.imageViewImage.image andScale:sender.scale];

        // present the modal view controller
        [self presentViewController:viewControllerZoom animated:YES completion:nil];

        // gracefully transition the image back to its original size
        [UIView animateWithDuration:0.5f animations:^{
            self.imageViewImage.transform = CGAffineTransformIdentity;
        }];
    }
    else if ( sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateCancelled ) {
        // revert to normal size on end
        [UIView animateWithDuration:0.5f animations:^{
            self.imageViewImage.transform = CGAffineTransformIdentity;
        }];
    }
    else if ( sender.scale >= 1.0f ) {
        // scale in place
        CGFloat scale = sender.scale;
        self.imageViewImage.transform = CGAffineTransformScale(CGAffineTransformIdentity, scale, scale);
    }
}
4

2 回答 2

0

我不这么认为,您需要继续使用手势附加到的现有视图并且用户已经在与之交互。我从未尝试过,但我想将该视图移动到模态视图控制器中是行不通的。调整视图大小应该可以工作,因此您可以更改视图并根据需要添加其他子视图来提供所需的 UI,而不是使用模式。

于 2013-09-29T15:24:57.937 回答
0

我不确定,但按照以下方式进行。- 让您的视图控制器(将要展示的)作为代表。- onGesture 事件在委托上频繁触发方法 - 在触发的方法中缩放或缩放您的视图。- 还在您的视图控制器上添加 PinchGesture(将显示)并使用处理程序进行缩放和缩放目的

于 2016-10-12T16:32:00.563 回答