微信摇一摇 摇动代码

-(void)accelerometer(UIAccelermeter*)accelcermeter didAccdlerate(UIAccelerrration*)acceleration

{

   Static NSInterger shakecount = 0;

   Static NSDate * shakeStart;

   NSDate * now  =[ [NSDate alloc]init];

   NSDate * checkdate = [[NSDate alloc]initWithTimeInterval:1.5f  sinceDaate:shakeStart];

 

   if([now compare:checkdate]==NSOrderedDescending || shaketart == nil)

 

  {

    shakeCount = 0;

 

    [shaketStart release];

 

    shakeStrat = [[NSdate alloc]init];

 

  }    

  [now releease];

  [checkDate release];

 

   if(fabsf(acceleration.x)>2.0||fabsf(acceleration.y)>2.0||fabsf(acceleration.z)>2.0)

 

  {

    shakeCount++;

    if(shakeCount>4)

    {

 

      //做你摇动想做的事情

      shakeCount = 0;

 

      [shakeStart release];

 

      shakeStart  = [[NSDate alloc ]init];

 

    }

 

  }

}


你可能感兴趣的:(微信摇一摇 摇动代码)