Touches, motion touch Event Response, touchesmotion

Source: Internet
Author: User

Touches, motion touch Event Response, touchesmotion

// Method to override the touch Event Response

1 // trigger this method (message sending) during touch 2-(void) touchesBegan :( NSSet <UITouch *> *) touches withEvent :( UIEvent *) event {3 UITouch * touch = [touches anyObject]; 4 CGPoint point = [touch locationInView: self. rootView. touchView]; // locationInView: obtains the coordinates of position 5 NSLog (@ "Touch start: %. 2f, %. 2f ", point. x, point. y); 6} 7 // trigger this event when the touch moves 8-(void) touchesMoved :( NSSet <UITouch *> *) touches withEvent :( UIEvent *) event {9 10 UITouch * touch = [touches anyObject]; 11 CGPoint point1 = [touch locationInView: self. rootView. touchView]; 12 CGPoint point2 = [touch previuslocationinview: self. rootView. touchView]; // previouslocationInView: obtains the coordinates of the previous vertex in the specified view. 13} 14 // This method is triggered when the touch ends (message sending) 15-(void) touchesEnded :( NSSet <UITouch *> *) touches withEvent :( UIEvent *) event {16 NSLog (@ "Touch end"); 17} 18 // in other cases, if you call or quit unexpectedly, run this method 19-(void) touchesCancelled :( NSSet <UITouch *> *) touches withEvent :( UIEvent *) event {20 21}
// Rewrite the method for mobile phone shake implementation

1 // call 2-(void) motionBegan :( UIEventSubtype) motion withEvent :( UIEvent *) event {3 NSLog (@ "Shake start "); 4} 5 // call 6-(void) motionEnded :( UIEventSubtype) motion withEvent :( UIEvent *) event {7 NSLog (@ "Shake end "); 8} 9 // call 10-(void) motionCancelled :( UIEventSubtype) motion withEvent :( UIEvent *) event {11 NSLog (@ "unexpectedly quit"); 12}

 

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.