ios摇一摇的实现

把下边的代码 放到UIVIEWCONTROLLER里,就能实现摇一摇效果

#pragma mark - Shake

- (BOOL) canBecomeFirstResponder

{

    return YES;

}

- (void) viewDidAppear:(BOOL)animated

{

    [super viewDidAppear:animated];

    [self becomeFirstResponder];

}

- (void) viewWillAppear:(BOOL)animated

{

    [self resignFirstResponder];

    [super viewWillAppear:animated];

}

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

{

    if (motion == UIEventSubtypeMotionShake) {

        NSLog(@"Shake..........");

    }

}

你可能感兴趣的:(ios摇一摇的实现)