2011-09-08 105 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