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 UIView
s.
精彩评论