iOS 摇一摇的实现

来源:互联网 发布:实用的软件项目 编辑:程序博客网 时间:2024/05/30 21:58

- (void)viewDidLoad

{

    [superviewDidLoad];

    [[UIApplication sharedApplication] setApplicationSupportsShakeToEdit:YES];

    [selfbecomeFirstResponder];

}


- (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(@"完成摇动后处理事件");

}


原创粉丝点击