您的位置:首页 > 移动开发 > IOS开发

在ios中实现摇一摇功能

2013-05-17 19:27 423 查看
- (void)viewDidLoad
{
[superviewDidLoad];
[[UIApplication
sharedApplication] setApplicationSupportsShakeToEdit:YES];
[selfbecomeFirstResponder];
}

- (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(@"完成摇动后处理事件");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: