IOS implementation shakes a shake

Source: Internet
Author: User

Shake function: Call the system comes with the accelerator, when the device shakes, the system calculates the accelerator's acceleration value, and then tells the device whether the shaking gesture, the system will only start and end of the movement to notify you, and will not be in the whole process of the movement to report to you every time the movement. For example, if you shake the device three times quickly, you will only receive a shake event.

To implement a shake gesture, you first need to make the view controller the first responder, and note that it is not a separate control. The most appropriate time to become the first responder is to release the first responder when the view is present and when the view disappears.

1-(BOOL) Canbecomefirstresponder2 {3     returnYES;4 }5 6-(void) Viewdidappear: (BOOL) Animated7 {8 [Super viewdidappear:animated];9 [self becomefirstresponder];Ten } One  A-(void) Viewdiddisappear: (BOOL) Animated - { - [Super viewdiddisappear:animated]; the [self resignfirstresponder]; -}

Then implement the Motionended method, because this method is called when the mobile phone is over.

1 -(void) motionended: (uieventsubtype) Motion withevent: (uievent *)event2{  3     if (motion = = uieventsubtypemotionshake) {4         NSLog (@ "  I am Shaker"); 5     }6 }

IOS implementation shakes a shake

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.