iOS 摇一摇的实现

- (void)viewDidLoad

{

    [super viewDidLoad];

    [[UIApplication sharedApplication] setApplicationSupportsShakeToEdit:YES];

    [self becomeFirstResponder];

}

 

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event

{

    //检测到摇动

}

 

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event

{

    //摇动结束

    if (event.subtype == UIEventSubtypeMotionShake) {

        //something happens

        [self test];

    }

}

 

- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event

{

    //摇动取消

}

 

- (BOOL)canBecomeFirstResponder {

    return YES;

}

 

-(void)test

{

    NSLog(@"完成摇动后处理事件");

}

 

posted on 2016-02-24 23:37  🌞Bob  阅读(147)  评论(0编辑  收藏  举报

导航