振动检测
来源:互联网 发布:mac 查看mysql版本 编辑:程序博客网 时间:2024/04/28 09:03
震动检测主要分为下面4个步骤,依次实现即可// step1 @interface UIWindow (MotionRecognizing)@end@interface UIResponder (MotionRecognizers)/** Registers the receiver for future motion events. The `action` message will be sent to the receiver when a motion event occurs and is not intercepted in the responder chain. The `action` selector must take exactly one parameter of type NSNotification. You must not add a motion recognizer more than once. */- (void) addMotionRecognizerWithAction:(SEL)action;/** You must call this before deallocating the receiver. */- (void) removeMotionRecognizer;@end
@implementation UIWindow (MotionRecognizing)- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent*)event{if (event.type == UIEventTypeMotion && event.subtype == UIEventSubtypeMotionShake) {[[NSNotificationCenter defaultCenter] postNotificationName:@"CPDeviceShaken" object:self]; }}@end@implementation UIResponder (MotionRecognizers)- (void) addMotionRecognizerWithAction:(SEL)action{[[NSNotificationCenter defaultCenter] addObserver:self selector:action name:@"CPDeviceShaken" object:nil];}- (void) removeMotionRecognizer{[[NSNotificationCenter defaultCenter] removeObserver:self name:@"CPDeviceShaken" object:nil];}@end
// step2: - (void) viewWillAppear:(BOOL)animated {[super viewWillAppear:animated];// Step 2 - Register for motion event:[self addMotionRecognizerWithAction:@selector(motionWasRecognized:)];}
// step3:- (void) viewDidDisappear:(BOOL)animated {// Step 3 - Unregister:[self removeMotionRecognizer];[super viewDidDisappear:animated];}
// step4- (void) motionWasRecognized:(NSNotification*)notif { // 震动后,在这里实现结果}
另外有实现屏幕震动的代码:
stackoverflow shake visual screen use coreanimation
- 振动检测
- iOS振动检测不出来
- 【Arduino官方教程第一辑】示例程序 6-2 用压电元件检测振动
- 振动窗口
- iPhone振动
- mobile振动
- 振动Vibrator
- 调用振动
- 弦振动
- 晶格振动
- Android 振动
- 悬臂梁振动
- 振动盘
- 振动传感器
- cordova 振动
- Windows Phone 7 体感开发指南(振动、GPS、重力感应、陀螺仪/罗盘、环境光/光线检测、趋近/贴近检测)
- 轴振动和轴承振动的区别
- 振动论坛---MATLAB
- vim、gvim在windows下中文乱码的终极解决方案
- Linux中断浅析
- java读取视频时长
- 投资理财的感受
- vc6.0连接access2007数据库
- 振动检测
- 提取出某日访问百度次数最多的那个IP
- 破解Android:谈谈Root与刷机
- hdu 1009 FatMouse' Trade
- MyEclipse 中各种 libraries 的含义
- CareerCup-BASE CASE AND BUILD
- uva 699 The Falling Leaves
- CV牛人牛事
- 网页去噪,获取网页正文相关开源项目