(IPhone/iPad Development) features related to mobile phone shake experience on iOS devices

Source: Internet
Author: User

I just created a function to shake the iOS device and trigger some experience. Now I searched the internet and read the development documentation. I feel that there are too many bad articles on the Internet, there are also a lot of articles that are reproduced and copied blindly, and the Implementation Principles have not yet been clarified. Instead of having to go online for time-consuming searches, it is better to take a look at the development documentation and quickly solve the problems that need to be solved. Specific implementation method: the iOS SDK has easily integrated the shake event, Just Like triggering the touch event. It should be noted that the current ViewController is set to the first responder first, then, when the app has a shake event, the program will automatically execute-(void) motionCancelled :( UIEventSubtype) motion withEvent :( UIEvent *) event-(void) motionBegan :( UIEventSubtype) motion withEvent :( UIEvent *) event-(void) motionEnded :( UIEventSubtype) motion withEvent :( UIEvent *) the event only needs to write the required functions in the corresponding trigger event. Code: set the first responder: [cpp]-(BOOL) canBecomeFirstResponder {return YES;}-(void) viewDidAppear :( BOOL) animated {[self canBecomeFirstResponder];} process the trigger Event: [cpp] # pragma mark-MotionShake event-(void) motionBegan :( UIEventSubtype) motion withEvent :( UIEvent *) Event {}-(void) motionEnded :( UIEventSubtype) motion withEvent :( UIEvent *) event {if (motion = UIEventSubtypeMotionShake) {NSLog (@ "Shake !!!!! !!!!!! ") ;}}-(Void) motionCancelled :( UIEventSubtype) motion withEvent :( UIEvent *) event {}

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.