user930195
user930195

Reputation: 432

How to create a drg & drop feature in an iPad app

I am just trying to create a sample ipad app where i have some objects present in left side of my screen which i want that user can able to drag those objects and drop it into right side main view.Then they can able to view and interact with that object.

How can i able to do this please elaborate?

Is there any sample/open source application available which i can refer for this?

Upvotes: 1

Views: 378

Answers (1)

Gypsa
Gypsa

Reputation: 11314

You need not to add some other library .You have to implement touches method. IN touch began you will get the position of the object.IN touch move you will modify the coordinate of that object and on touch ended when you left you will get you object at new position. and you can access your object properly.

ex:-

CGPoint startLocation;

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
     CGPoint pt = [[touches anyObject] locationInView:self];
     startLocation = pt;
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
     CGPoint pt = [[touches anyObject] locationInView:self];
     CGRect frame = [self frame];
     frame.origin.x += pt.x - startLocation.x;
     frame.origin.y += pt.y - startLocation.y;
     [self setFrame:frame];
}

You need to do something like this.

Upvotes: 2

Related Questions