- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//1.让视图控制器开启摇一摇功能
[[UIApplication sharedApplication] setApplicationSupportsShakeToEdit:YES];
//2.设置当前的视图控制器为第一响应者
[self becomeFirstResponder];
}
//然后去实现那几个方法就可以了
- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//检测到摇动
NSLog(@"正在摇一摇");
}
- (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//摇动取消
}
- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//摇动结束
if (event.subtype == UIEventSubtypeMotionShake) {
//something happens
//完成摇一摇的功能
}
}
ios 摇一摇功能
最新推荐文章于 2024-09-10 17:30:17 发布