david
david

Reputation: 139

Draw a rectangle which is draggable

If I draw a rectangle on a frame 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.

Upvotes: 0

Views: 1007

Answers (1)

tipycalFlow
tipycalFlow

Reputation: 7644

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.

Upvotes: 1

Related Questions