首页 > 代码库 > 摇一摇和手势
摇一摇和手势
1.设置摇动,或要使他变要第一响应者
[[UIApplication sharedApplication]setApplicationSupportsShakeToEdit:YES];
[self canBecomeFirstResponder];
2.实现下面几个函数来控制摇一摇的触发的动作
- (BOOL)canBecomeFirstResponder
{
return YES;// default is NO
}
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
NSLog(@"开始摇动手机");
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
NSLog(@"stop");
UIAlertView *yaoyiyao = [[UIAlertView alloc]initWithTitle:@"温馨提示:" message:@"麻辣疙疤籽" delegate:self cancelButtonTitle:@"cancel"otherButtonTitles:@"back",nil ];
[yaoyiyao show];
}
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
NSLog(@"取消");
}
3.提示框
UIAlertView *yaoyiyao = [[UIAlertView alloc]initWithTitle:@"温馨提示:" message:@"您有新消息" delegate:self cancelButtonTitle:@"cancel"otherButtonTitles:@"back",nil ];
@protocol UIAlertViewDelegate <NSObject> 这里的协议可实现提示框里的按钮的功能
4.手势的添加
UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(back:)]; //设置手势
[self.view addGestureRecognizer:tap];//将手势添加到视图上
5.webview上设置返回按钮的做法
if (webView.canGoBack==YES) {
[webView goBack];
}
else
[self.navigationController popViewControllerAnimated:YES];
摇一摇和手势