博客> 手机摇一摇功能
手机摇一摇功能
2017-09-24 02:11 评论:0 阅读:295 shuang_ios

import

  • (void)viewDidLoad { // 设置允许摇一摇功能 [UIApplication sharedApplication].applicationSupportsShakeToEdit = YES; // 并让自己成为第一响应者 [self becomeFirstResponder]; }

  • (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { NSLog(@"开始摇动");

    return; }

  • (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event { NSLog(@"取消摇动"); return; }

  • (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (event.subtype == UIEventSubtypeMotionShake) { // 判断是否是摇动结束 NSLog(@"摇动结束"); [self RandomNumber]; [self shakeshake];

    } return; }

  • (void)shakeshake { AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); }
收藏
0
sina weixin mail 回到顶部