iOS 摇一摇的实现-备用
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS 摇一摇的实现-备用相关的知识,希望对你有一定的参考价值。
- (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 摇一摇的实现-备用的主要内容,如果未能解决你的问题,请参考以下文章
Android手机摇一摇的实现SensorEventListener