2011-09-08 102 views
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 s完成。

+0

thx mate,这很有帮助 – david