处理捏合缩放手势

发布于 2024-11-28 09:12:47 字数 141 浏览 3 评论 0原文

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

I am working with the apple sample code _TapToZoom. They handled single, double taps using UIGestureRecognizers to scale the scrollview(with image) when user taps. Now I would like to implement the same functionality when user pinch zooming on the image scrollview. I am going through the so many links, but not helpful. Please help me to resolve this....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断念 2024-12-05 09:12:47

添加手势识别器,如下所示:

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");
            }

        }

Add the gesture recognizer like so:

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

This condition will check if the gesture recognizer is a UIPinhcgestureRecognizer and the inner conditions check if the user has pinched or zoomed:

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

        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文