您的位置:首页 > 移动开发 > Objective-C

Objective-C -------简单版的摇一摇

2016-07-11 00:00 375 查看
摘要: 简单版的摇一摇

1.将application的applicationSupportsShakeToEdit属性改成YES

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

[self.window makeKeyAndVisible];

self.window.rootViewController = [[ViewController alloc]init];

self.window.backgroundColor = [UIColor whiteColor];

application.applicationSupportsShakeToEdit = YES;

return YES;
}

2.设置响应

- (BOOL)canBecomeFirstResponder{
return YES;
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self becomeFirstResponder];
}

- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self resignFirstResponder];
}

3.实现功能

-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
NSLog(@"begin");
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
NSLog(@"end");

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: