// Start Touching
-(void) Touchesbegan: (nsset *) touches withevent: (uievent *) event{
//Nsset Collection arrays are similar in that they are used to mount multiple objects, But the difference is set unordered
// get arbitrary objects in set set
[Touches anyobject];
// turn set set to array
nsarray *arr = touches. allobjects;
uitouch *t = [touches anyobject];
cgpoint p = [t locationinview:self. View];
NSLog (@ "x=%f y=%f", p.x, p.y);
NSLog (@ "%@",nsstringfromcgpoint(p));
// convenient for all pictures
for (uiimageview *iv in self.) imageviews) {
// determine which picture is touching
if (cgrectcontainspoint(Iv. Frame, p)) {
// change the touch image into a property so that methods such as the move touch location method can call
Self. Dragview = IV;
break;
}
}
}
// Mobile Touch Location
-(void) touchesmoved: (nsset *) touches withevent: (uievent *) event{
uitouch *t = [touches anyobject];
cgpoint p = [t locationinview:self. View];
// let touch the center position of the picture equal to the location of the touch
Self. Dragview. Center = p;
}
// End Touch
-(void) touchesended: (nsset *) touches withevent: (uievent *) event{
uitouch *t = [touches anyobject];
cgpoint p = [t locationinview:self. View];
NSLog (@ "end%@",nsstringfromcgpoint(p));
// end Touch, unbind the touch's coordinates from the picture
Self. Dragview = nil;
}
// If a call comes in when an unexpected interruption occurs,
-(void) touchescancelled: (NSSt *) touches withevent: (uievent *) event{
uitouch *t = [touches anyobject];
cgpoint p = [t locationinview:self. View];
NSLog (@ "cancell%@",nsstringfromcgpoint(p));
}
the control from the original parent view Self . View move to a new parent view Self . Leftview , coordinate offset value correction method
// when the parent view changes, you need to convert the coordinates relative to the original parent view to the coordinates relative to the new parent view.
cgpoint oldcenter = self. Dragview. Center;
cgpoint newcenter = [self. View convertpoint: Oldcenter toview:self. Leftview];
[Self. Leftview addsubview:self. Dragview];
Self. Dragview. Center = newcenter;
Record the number of controls added to the view
By the number of items in the view sub-view array
Self. Rightlabel. text = [nsstring stringwithformat:@ '%d ',self. Rightview. subviews. Count];
leave the part of the view edge out of the display
Storyboard in the View properties selected Drawing in the Clip subsubviews tick
Lan Yi Education September 28 Records