@ Interface placement () {@ private cgpoint startpoint;} @ end @ implementation aplmovemeview @ synthesize placardview; // @ synthesize nextdisplaystringindex;-(void) setupplacecardview :( aplplacardview *) _ placecardviews {self. placardview = _ placecardviews;}-(void) touchesbegan :( nsset *) touches withevent :( uievent *) event {// we only support single touches, so anyobject retrieves just that touch from touches. Uitouch * Touch = [touches anyobject]; // only move the placard view if the touch was in the placard view. If ([Touch view]! = Self. placardview) {// in case of a double tap outside the placard view, update the placard's display string. if ([Touch tapcount] = 2) {[self setupnextdisplaystring];} return;} cgpoint point = [[touches anyobject] locationinview: Self]; startpoint = point; // animate the first touch. cgpoint touchpoint = [Touch locationinview: Self]; [self animatefirsttouchatpoint: touchpoint];}-(void) touchesmoved :( nsset *) touches withevent :( ui* event *) event {uitouch * Touch = [touches anyobject]; // If the touch was in the placardview, move the placardview to its location. if ([Touch view] = self. placardview) {// cgpoint locationss = [Touch locationinview: Self]; // self. placardview. center = locationss; // calculates the displacement = Current Position-starting position cgpoint point = [[touches anyobject] locationinview: Self]; // float dx = point. x-startpoint. x; float DY = point. y-startpoint. y; // calculate the moving View Center cgpoint newcenter = cgpointmake (startpoint. x, self. center. Y + dy);/* restrict users from holding Views out of the screen */float halfx = cgrectgetmidx (self. bounds); // returns the left boundary of the X coordinate newcenter. X = max (halfx, newcenter. x); // The right boundary of the X coordinate newcenter. X = min (self. superview. bounds. size. width-halfx, newcenter. x); // y coordinate float Halfy = cgrectgetmidy (self. bounds); newcenter. y = max (Halfy, newcenter. y); newcenter. y = min (self. superview. bounds. size. height-Halfy, newcenter. y); // move view self. placardview. center = newcenter; return ;}- (void) touchesended :( nsset *) touches withevent :( uievent *) event {uitouch * Touch = [touches anyobject]; // If the touch was in the placardview, bounce it back to the center. if ([Touch view] = self. placardview) {/* Disable User interaction so subsequent touches don't interfere with animation until the placard has returned to the center. interaction is reenabled in animationdidstop: Finished :. */self. userinteractionenabled = no; [self animateplacardviewtocenter]; return ;}}
You can use the built-in IOS instance moveme to drag images and drag images within the screen. Below are some of the changed code: