如何像 uiscrollview 上的 uiimageview 那样调整 uiview 的大小?

发布于 2024-12-19 11:42:26 字数 1048 浏览 2 评论 0原文

我需要为用户提供裁剪图像的功能。我在一个视图上显示 uiimageview,并在该视图上显示另一个视图,该视图可像小盒子一样移动。移动盒子时,它会给我坐标,据此我将从 uiimageview 创建一个新图像。通过这种方式,我提供了裁剪图像的功能。

到目前为止,我给出了要裁剪的框的固定高度宽度,但现在我需要提供类似 2 个手指触摸的功能,我的裁剪框会根据我的手指位置调整大小,就像苹果的 ScrollviewSuite 示例一样。我正在做以下事情:

 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{    
    UITouch *touch = [[event allTouches] anyObject];

    NSUInteger tapCount = [touch tapCount];
    UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTap:)];
    [twoFingerTap setNumberOfTouchesRequired:2];
    [newView addGestureRecognizer:twoFingerTap];

    CGPoint touchLocation = [touch locationInView:self.view];

    oldX = touchLocation.x;
    oldY = touchLocation.y;
}


- (void)handleTwoFingerTap:(UIGestureRecognizer *)gestureRecognizer 
{
    CGRect frame = newView.frame; \\newframe is the crop box
    frame.size.height += 100;
    newView.frame = frame;
}

但通过这种方式,我只能以静态方式增加高度。我应该怎么做才能获取两个手指的触摸和坐标?任何帮助将不胜感激。谢谢。

I need to give functionality to user of cropping the image. I am displaying the uiimageview on a view and on that another view is being shown which is movable like a small box.on moving the box, it will give me the coordinates and as per that I will create a new image from the uiimageview. In such a way I am giving the functionality of a cropping Image.

Till now I was giving a fixed height width of the box to crop,But now I need to give a functionality like on 2 fingers touch,my crop box gets resized as per my fingers' position like that of ScrollviewSuite example of apple. I am doing following :

 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{    
    UITouch *touch = [[event allTouches] anyObject];

    NSUInteger tapCount = [touch tapCount];
    UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTap:)];
    [twoFingerTap setNumberOfTouchesRequired:2];
    [newView addGestureRecognizer:twoFingerTap];

    CGPoint touchLocation = [touch locationInView:self.view];

    oldX = touchLocation.x;
    oldY = touchLocation.y;
}


- (void)handleTwoFingerTap:(UIGestureRecognizer *)gestureRecognizer 
{
    CGRect frame = newView.frame; \\newframe is the crop box
    frame.size.height += 100;
    newView.frame = frame;
}

But in this manner I am just able to increase the height in static manner. What should i do to fetch two finger touches and coordinates? Any help will be much appreciated. Thank you.

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

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

发布评论

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

评论(1

阳光①夏 2024-12-26 11:42:26

handleTwoFingerTap 隐藏 self.view 和可见滚动视图..意味着您必须采用一个 uiview 和一个滚动视图 ..scrollview 进行缩放

handleTwoFingerTap hide self.view and visible scroll view..means you have to take one uiview and one scrollview ..scrollview for Zooming

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