- (void)viewDidLoad
{
[super viewDidLoad];
[[UIApplication sharedApplication] setApplicationSupportsShakeToEdit:YES];
[self becomeFirstResponder];
}
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//检测到摇动
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//摇动结束
if (event.subtype == UIEventSubtypeMotionShake) {
//something happens
[self test];
}
}
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//摇动取消
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
-(void)test
{
NSLog(@"完成摇动后处理事件");
}
本文介绍了如何在iOS应用中实现摇动手势触发特定事件处理的功能,包括摇动手势的开始、结束和取消检测,以及如何在事件结束时执行自定义操作。
374

被折叠的 条评论
为什么被折叠?



