iOS 测试手机是否震动(类似微信摇一摇功能)

1、在  AppDelegate.h

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


    application.applicationSupportsShakeToEdit = YES;


    return YES;

}


2、在ViewController.h 

-(void)viewDidAppear:(BOOL)animated {

    [super viewDidAppear:animated];

    [self becomeFirstResponder];

}


- (void)viewWillDisappear:(BOOL)animated {

    [self resignFirstResponder];

    [super viewWillDisappear:animated];

}


-(BOOL)canBecomeFirstResponder {

    return YES;

}


- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event

{

    if (motion == UIEventSubtypeMotionShake) {

        NSLog(@"手机震动了");

    }else

    {

        

    }

}


转载请注明出处 : http://write.blog.csdn.net/postedit

iOS交流群:496146057

你可能感兴趣的:(iOS,-,设备控件,iOS,-,文件)