0

我正在使用苹果示例代码 _TapToZoom。当用户点击时,他们使用 UIGestureRecognizers 处理单次、双击来缩放滚动视图(带图像)。现在我想在用户捏缩放图像滚动视图时实现相同的功能。我正在浏览这么多链接,但没有帮助。请帮我解决这个问题......

4

1 回答 1

1

像这样添加手势识别器:

UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(<your gesture handling callback>:)]; 
[self.view addGestureRecognizer:pinch];
[pinch release];

此条件将检查手势识别器是否为 UIPinhcgestureRecognizer,内部条件将检查用户是否已捏合或缩放:

if ([sender isKindOfClass:[UIPinchGestureRecognizer class]]) {
        [gesture setString:kPinchGesture];
        if (((UIGestureRecognizer*)sender).state == UIGestureRecognizerStateEnded) {
            if (((UIPinchGestureRecognizer*)sender).scale < 1) {
                NSLog(@"Pinched");
            }
            else {
                NSLog(@"Zoomed");
            }

        }
于 2011-08-09T09:58:30.437 回答