如何像 uiscrollview 上的 uiimageview 那样调整 uiview 的大小?
我需要为用户提供裁剪图像的功能。我在一个视图上显示 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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