绘制一个可拖动的矩形

时间:2011-09-08 09:46:53

标签: ios ipad uiview ios4

如果我在框架上绘制一个矩形,然后我想将此矩形拖动到此框架上的不同位置。我怎么能这样做?如果我的描述不清楚,请添加评论。这可能有点令人困惑。

1 个答案:

答案 0 :(得分:1)

您可以使用任何背景图片创建UIView,并通过将其框架设置为yourView.center = CGPointMake(x,y);

将其移动到窗口上

您可以使用touchesBegantouchesMovedtouchesEnded方法中的任意/全部方法检测触摸点,如下所示:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch =[touches anyObject];
CGPoint currentPoint =[touch locationInView:self.view];//point of touch
}

这些方法将在UIViewController中声明。作为示例代码,您可以参考我的github项目,在该项目中,我将项目从一个UITableView拖到另一个UITableView,我已使用UIView完成了该项目。

相关问题