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

检测手机的震动需要导入

import 框架

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

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

你可能感兴趣的:(iOS开发中如何检测手机在摇一摇)