开发者

Draw a rectangle which is draggable

开发者 https://www.devze.com 2023-04-03 06:23 出处:网络
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 uncl

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

精彩评论

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