美文网首页
iOS开发中如何检测手机在摇一摇

iOS开发中如何检测手机在摇一摇

作者: 不疯魔难以成佛 | 来源:发表于2016-07-14 13:55 被阅读0次

检测手机的震动需要导入

import <AVFoundation/AVFoundation.h>框架

然后实现下面方法即可
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
if (motion == UIEventSubtypeMotionShake) {
NSLog(@"手机开始摇动");
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//让手机震动
}
}

  • (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {
    //摇动取消
    }

相关文章

网友评论

      本文标题:iOS开发中如何检测手机在摇一摇

      本文链接:https://www.haomeiwen.com/subject/isvejttx.html