码迷,mamicode.com
首页 > 其他好文 > 详细

摇一摇和手势

时间:2014-08-30 09:57:19      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:io   ar   cti   log   sp   on   ad   c   ef   

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];

摇一摇和手势

标签:io   ar   cti   log   sp   on   ad   c   ef   

原文地址:http://www.cnblogs.com/niang123/p/3946082.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!