Lan Yi Education September 28 record

Source: Internet
Author: User
Tags set set

// 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.