How to Move an Object Using Drag in XCode

XCode is the programming model language for iPhone apps. iPhone supports drag and drop operations on the user's phone, so you can support the operations using XCode's drag and drop functions. You must define the source to drag and the location at which the user "drops" the image or file. Drag-and-drop is a useful tool for an iPhone app, because it is a familiar and intuitive utility for users.

Instructions

    • 1

      Open your XCode development software and the iPhone app project you want to edit. Open the XCode source code file you want to use to create the drag-and-drop functionality.

    • 2

      Create a pointer to the files or image you want to move. The following code points to one image named image1.jpg:

      NSArray *images= [NSArray arrayWithObjects:"image1.jpg", nil];

    • 3

      Start the drag operation. The following code starts the drag operation on the phone:

      dragImage = [[NSWorkspace sharedWorkspace] *images];

    • 4

      Set the position at which you want to drag and drop the file or image. In this example the image is dragged and dropped to the upper left corner of the window:

      pos = [self convertPoint:[theEvent locationInWindow] fromView:nil];
      pos.x = 0;
      pos.y = 0;

Related Searches:

References

Comments

Related Ads

Featured