iOS Touch events

Source: Internet
Author: User

{//Start touch point
Cgpoint _startpoint;

}

-(ID) initWithFrame: (CGRect) frame
{
self = [super Initwithframe:frame];
if (self) {
Initialization code
Add color to TestView
Self.backgroundcolor=[uicolor Redcolor];
Blocking
Self.userinteractionenabled=no;


}
return self;

}

What do you want to do? When you touch an event, execute the scheduled execution event code inside the Touchbegan (when you start to touch it, take a look at it.)
When a touch event occurs, the method executes only once
-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event
{
NSLog (@ "I'm going to start touching.");
Self.backgroundcolor=[uicolor greencolor];//Click to change color
Self.backgroundcolor=[uicolor colorwithred:krandomcolor green:krandomcolor Blue:krandomcolor alpha:1];
Remove the coordinates of the finger touch screen
Cgpoint sp=[[touches Anyobject] locationinview:self];
NSLog (@ "%@", Nsstringfromcgpoint (sp));
_startpoint=[[touches Anyobject] locationinview:self];
NSLog (@ "%@", Nsstringfromcgpoint (_startpoint));

}


One touch event has not ended and will always call the method (never touch it, always touch it)
-(void) touchesmoved: (Nsset *) touches withevent: (Uievent *) event
{
NSLog (@ "touch ing");
Self.backgroundcolor=[uicolor colorwithred:krandomcolor green:krandomcolor blue:krandomcolor alpha:1];//Click to move always change color
Take the point in the move
Cgpoint nowpoint=[[touches Anyobject] locationinview:self];
NSLog (@ "%@", Nsstringfromcgpoint (Nowpoint));
CGFloat x=nowpoint.x-_startpoint.x;
CGFloat Y=nowpoint.y-_startpoint.y;
Cgpoint Centerpoint=cgpointmake (self.center.x+x,self.center.y+y);
Self.center=centerpoint;

}


One touch event ends and the method is executed (finished)
-(void) touchesended: (Nsset *) touches withevent: (Uievent *) event
{
NSLog (@ "ended.");

}


Touch events interrupted by other events (interrupted by someone)
-(void) touchescancelled: (Nsset *) touches withevent: (Uievent *) event
{

}

iOS Touch events

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.