捏合手势和单点触摸

发布于 2024-10-11 08:39:56 字数 213 浏览 2 评论 0原文

我有几个问题,
1)我在视图上有一个 UIImageView 控件。我想添加捏合手势以允许放大和缩小。
2)我需要将附加图像放置在基本图像之上,这些图像不需要缩放,但它们需要保留在放置在基本图像上的原始位置。

现在的问题是......
如何测试单次触摸和拖动,同时寻找基础图像的捏合和拉伸手势?

感谢大家对此提供的帮助。

保重
托尼

I have a couple of questions,
1) I have a UIImageView control on a view. I would like to add the pinch gesture to allow zooming in and out.
2) I have the requirement to drop additional images on top of the base image, these images do not need to zoom, but they will need to remain in the original location that they were placed on the base image.

Now the question is this....
How do I test for a single touch and drag around, while also looking for a pinch and stretch gesture for the base image?

Thanks for everyone helps on this.

take care
tony

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

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

发布评论

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

评论(1

不甘平庸 2024-10-18 08:39:56

在 viewdidload 中添加此内容:

UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];

    [imageView addGestureRecognizer:pinchGesture];  //imageView is your base image 
    [pinchGesture release];




//Zooming of image
-(IBAction)handlePinchGesture:(UIPinchGestureRecognizer *) sender
{

    if (pictureTimer) {  //This is NSTimer. set pictureTimer=1 in viewdidLoad
        return;
    }


    CGFloat factor = [(UIPinchGestureRecognizer *) sender scale];
    if(factor >1)
    {
        sender.view.transform =CGAffineTransformMakeScale(lastScaleFactor +(factor-1), lastScaleFactor +(factor-1));
    }
    else {
        sender.view.transform=CGAffineTransformMakeScale(lastScaleFactor * factor, lastScaleFactor*factor);
    }

    if (sender.state==UIGestureRecognizerStateEnded) {
        if (factor>1) {
            lastScaleFactor +=(factor-1);
        }
        else {
            lastScaleFactor*= factor;
        }

    }

}

您将拉伸到基本图像。

Add this in viewdidload:

UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];

    [imageView addGestureRecognizer:pinchGesture];  //imageView is your base image 
    [pinchGesture release];




//Zooming of image
-(IBAction)handlePinchGesture:(UIPinchGestureRecognizer *) sender
{

    if (pictureTimer) {  //This is NSTimer. set pictureTimer=1 in viewdidLoad
        return;
    }


    CGFloat factor = [(UIPinchGestureRecognizer *) sender scale];
    if(factor >1)
    {
        sender.view.transform =CGAffineTransformMakeScale(lastScaleFactor +(factor-1), lastScaleFactor +(factor-1));
    }
    else {
        sender.view.transform=CGAffineTransformMakeScale(lastScaleFactor * factor, lastScaleFactor*factor);
    }

    if (sender.state==UIGestureRecognizerStateEnded) {
        if (factor>1) {
            lastScaleFactor +=(factor-1);
        }
        else {
            lastScaleFactor*= factor;
        }

    }

}

Your will get stretch to your base image.

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