● 监控摇一摇的方法
● 方法1:通过分析加速计数据来判断是否进行了摇一摇操作(比较复杂)
● 方法1:通过分析加速计数据来判断是否进行了摇一摇操作(比较复杂)
● 方法2:iOS自带的Shake监控API(非常简单)
● 判断摇一摇的步骤:实现3个摇一摇监听方法
● - (void)motionBegan:(UIEventSubtype)motion withEvent:
(UIEvent *)event /** 检测到摇动 */
● - (void)motionCancelled:(UIEventSubtype)motion
withEvent:(UIEvent *)event /** 摇动取消(被中断) */
● - (void)motionEnded:(UIEventSubtype)motion withEvent:
(UIEvent *)event /** 摇动结束 */
#import "HMViewController.h" #import <sys/socket.h> @interface HMViewController () @end @implementation HMViewController - (void)viewDidLoad { [super viewDidLoad]; Class c = NSClassFromString(@"UINavigationTransitionView"); UIView *view = [[c alloc] init]; NSLog(@"%@", view); // UINavigationController *nav = [[UINavigationController alloc] init]; // NSLog(@"%@", nav.view.subviews); } #pragma mark - 实现相应的响应者方法 /** 开始摇一摇 */ - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { NSLog(@"motionBegan"); } /** 摇一摇结束(需要在这里处理结束后的代码) */ - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { // 不是摇一摇运动事件 if (motion != UIEventSubtypeMotionShake) return; NSLog(@"motionEnded"); } /** 摇一摇取消(被中断,比如突然来电) */ - (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event { NSLog(@"motionCancelled"); } @end