//只需要让这个Controller本身支持摇动 //同时让他成为第一相应者: - (void)viewDidLoad { [super viewDidLoad]; [[UIApplicationsharedApplication] setApplicationSupportsShakeToEdit:YES]; [selfbecomeFirstResponder]; } //然后去实现那几个方法 - (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { //检测到摇动 } - (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event { //摇动取消 } - (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { //摇动结束 if (event.subtype == UIEventSubtypeMotionShake) { //something happens } }
iOS摇一摇功能方法实现
最新推荐文章于 2023-07-12 11:53:09 发布