开发者

Draw a rectangle which is draggable

If I draw a rectangle on a frame开发者_StackOverflow社区 and then I want to drag this rectangle to different positions on this frame. How could I do this? Please add comments if my description is unclear. It might be a bit confusing.


You can create a UIView with any background image and move it on a window by setting its frame as yourView.center = CGPointMake(x,y);

You can detect the point of touch using any/all of touchesBegan , touchesMoved or touchesEnded methods as follows :

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

These methods are to be declared in a UIViewController. As sample code, you can refer to my github project in which I drag an item from one UITableView to another UITableView which I've accomplished using UIViews.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜