iOS 摇一摇功能的实现

1、首先需要在AppDelegate中进行如下设置

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    //引用程序可以监听摇一摇手势。
    application.applicationSupportsShakeToEdit = YES;
    
    
    return YES;
}

2、在要进行摇一摇的界面编写下面代码

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    NSLog(@"摇一摇开始");
}


- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    NSLog(@"摇一摇结束");
}

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



你可能感兴趣的:(iOS摇一摇)