iOS 摇一摇功能的实现

来源:互联网 发布:精华乳和精华液 知乎 编辑:程序博客网 时间:2024/05/16 12:46

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(@"摇一摇取消");
}



1 0
原创粉丝点击