检测iphone晃动

来源:互联网 发布:淘宝u站9块邮 编辑:程序博客网 时间:2024/04/28 07:23

 

/**        Module Name:     UIAccelerometer        Description:     Explain how to use   UIAccelerometer        Author:           Su XinDe        Created:          1:06  12/27/2011         Last Change:     1:06  12/27/2011   */               //UIAccelerometer - (void)viewDidLoad{    //......    UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer];    accelerometer.delegate = self;    accelerometer.undateInterval = 1.0f / 60.0f;  //tiem interval , 60 times per second, the max support value is 100 times per second    //......}- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceletration *)acceleration{    //Log the coordinate value changing when you shake the phone    //NSString *numberOfShake = [[NSStirng alloc] initWithFormat:@"x:%g\ty:%g\tz:%g",acceleration.x,acceleration.y,acceleration.z];    //shakeValueLabel.text = numberOfShake;    //[numberOfShake release];        //inspecting the shaking, and do the thing you want the phone to do    if(fabsf(acceleration.x)>2.0||fabsf(acceleration.y>2.0)||fabsf(acceleration.z)>2.0)    {        // do the operation you want to do        //just like        //NSLog(@"Shaking movement inspected");    } }
参考: http://hi.baidu.com/suxinde2009/item/60f003ebacb4cde9fb42ba53

原创粉丝点击