Shake a Shake

Source: Internet
Author: User

#import <AudioToolbox/AudioToolbox.h>

-(void) viewdidload {

[Super viewdidload];

additional setup after loading the view, typically from a nib.

// in IOS , audio includes short-acting audio and music , the implementation of short- acting audio is System Audiotoolbox, music playback uses Avfoundation frame

//Short -Acting audio : The playback process is not controllable and lasts no more than a few seconds

// Define a system sound ID

systemsoundid soundid;

// set up resources to play short-acting audio

Audioservicescreatesystemsoundid (__bridge cfurlref _nonnull) ([[NSBundle mainbundle] urlforresource:@ "Shake" withextension:@ "wav"] ), &soundid);

// Set the effect of vibration , need the real machine

Audioservicesplayalertsound (ksystemsoundid_vibrate);

audioservicesplaysystemsound(ksystemsoundid_vibrate);

// Play short-acting audio

audioservicesplaysystemsound(soundid);

Very simply, you just need to let the controller itself support shaking//and make him the first corresponding person:
    [[Uiapplicationsharedapplication] setapplicationsupportsshaketoedit:yes];     [Selfbecomefirstresponder];

}

shake a shake depends on the principle of gravity induction

-(void) Motionbegan: (uieventsubtype) motion withevent: (uievent *) event {

// Define a system sound ID

systemsoundid soundid;

// set up resources to play short-acting audio

Audioservicescreatesystemsoundid (__bridge cfurlref _nonnull) ([[NSBundle mainbundle] urlforresource:@ "Shake" withextension:@ "wav"] ), &soundid);

// Set the effect of vibration , need the real machine

//Audioservicesplayalertsound (ksystemsoundid_vibrate);

audioservicesplaysystemsound(ksystemsoundid_vibrate);

// Play short-acting audio

audioservicesplaysystemsound(soundid);

NSLog(@ " Shake start ");

}

-(void) motionended: (uieventsubtype) motion withevent: (uievent *) event {

NSLog(@ " Shake end ");

}

-(void) motioncancelled: (uieventsubtype) motion withevent: (uievent *) event {

NSLog(@ " Shake cancel ");

}

Shake a Shake

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.