0

I am having one view in ipad. On that view , I am having four buttons. Now when I click on that button , one view is opening with some fixed height,width,x position and y position. I want to make this new view dock-able. I mean I want to drag this view to anywhere on that big view.

Curious_k.shree
  • 990
  • 2
  • 18
  • 37

2 Answers2

0

Implement the following:

  1. – touchesBegan:withEvent:

  2. – touchesMoved:withEvent:

  3. – touchesEnded:withEvent:

  4. – touchesCancelled:withEvent:

And use the locations of touch to set the frame of the uiview. Its not complicated to do so.

A quick google search yielded this tutorial.

Praveen S
  • 10,355
  • 2
  • 43
  • 69
0

You can optimize this in your situation..

 -(void)dragging:(UIPanGestureRecognizer *)gesture
{
if(gesture.state == UIGestureRecognizerStateBegan)
{
//NSLog(@"Received a pan gesture");
self.panCoord = [gesture locationInView:gesture.view];


}
CGPoint newCoord = [gesture locationInView:gesture.view];
float dX = newCoord.x-panCoord.x;
float dY = newCoord.y-panCoord.y;

gesture.view.frame = CGRectMake(gesture.view.frame.origin.x+dX,          gesture.view.frame.origin.y+dY, gesture.view.frame.size.width, gesture.view.frame.size.height);
}