第一种
1、在AppDelegate.h中进行如下设置:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
application.applicationSupportsShakeToEdit = YES;
}
2、在你需要对晃动事件进行处理的ViewController中添加如下代码:
-(BOOL)canBecomeFirstResponder {
return YES;
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated {
[self resignFirstResponder];
[super viewWillDisappear:animated];
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion == UIEventSubtypeMotionShake) {
NSLog(@"检测到晃动");
}
}
3、在模拟器中测试晃动,按组合键:Ctrl + Win + Z
第二种:利用UIAccelerometer加速器来检测
- (void)viewDidLoad
{
UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer];
accelerometer.delegate = self;
accelerometer.undateInterval = 1.0f / 60.0f;
}
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceletration *)acceleration
{
if(fabsf(acceleration.x)>2.0||fabsf(acceleration.y>2.0)||fabsf(acceleration.z)>2.0)
{
//NSLog(@"检测到晃动");
}
}
分享到:
相关推荐
ios应用程序检测新版本,实例化该类,直接传递一个App在苹果AppStore上的ID,就可以实现版本更新功能。
Iphone快捷方式管理器源码,C#源码
本书全面探讨了iPhone平台的两种编程方式——Web开发和SDK编程。全在Web开发方面,分别介绍了三个iPhone Web库,即WebKit、iUI和Canvas,并讨论了Web开发环境Dashcode,最后阐述Web应用程序的调试。在SDK开发方面,...
【应用】-PictureMe(iPhone人脸检测APP).7z
IOS应用源码之【应用】PictureMe(iPhone人脸检测APP).rar
一、黑屏,无背光灯,有显示 二、有背光灯,黑屏 三、白屏、花屏(换LCD无效)
AnyChat for iPhone是专为IOS平台量身打造的一款即时通讯平台,可以实现双向音视频交互、电视直播、音视频上传、文字交流、文件传输等功能,提供C++和Objective-C两种编程接口可二次开发,应用程序界面及业务流程...
IOS应用源码之【应用】-PictureMe(iPhone人脸检测APP).rar
iPhone狂:约会iPhone
苹果在线商店维护检测工具是一款帮你检测iphone7大陆下载页面网址是否维护完毕的工具,苹果秋季发布会上正式发布了iphone7产品,此次iphone7将于2016年9月9日下午3点正式接受预定。相信很多想要买iphone7的用户这个...
iphone X iphone 8 原型框 iphone X iphone 8 原型框
NULL 博文链接:https://374016526.iteye.com/blog/1156908
iphone crash符号化工具 ,GUI界面操作,鼠标党的福音
iphone
根据网上资源扩展UIDevice类,完善增加设备检测函数;修改网上提供的给iPhone 数字键盘添加客制化按钮代码,使其兼容横竖屏,及iPad和iPhone。
一种基于Checkm8漏洞的iPhone取证方法研究.docx
Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码...
iphoneos-arm iPhone 必备工具
用preference方式实现的仿iPhone开关