矩形将被视为两个点,第一个点将是 touchBegan 点,在 touchMove 上将是第二个点,矩形将根据用户手指的移动动态绘制,(就像当您单击桌面并移动桌面时)鼠标您将获得动态矩形)。
Thanks
好的,这是你如何绘制矩形的方法touchesMoved
(使用@NektotouchesBegan
存储矩形的起点)。
假设您保留了我们正在绘制的 UIView 的引用并调用它drawnView
.
In touchesBegan
,我们将框架的原点设置为drawnView
Here is touchesMoved
:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent*)event
{
// We only take care of a single touch
if ([touches count] == 1)
{
UITouch *touch = [touches anyObject];
// Find the width and height of the rect
CGRect drawnFrame = drawnView.frame
drawnFrame.size.width = [touch locationInView:parentView].x - drawnFrame.origin.x
drawnFrame.size.height = [touch locationInView:parentView].y - drawnFrame.origin.y
[drawnView setFrame:drawnFrame];
}
}
不要复制粘贴该代码,我没有在 Xcode 或其他任何东西中编写它。它可能会有错误(肯定)。但我希望它能帮助您找到解决方案。请小心,如果您将手指拖动到顶部或左侧(高度和宽度为负值),我无法判断它会如何表现。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)