在ipad中处理设备运动

时间:2012-12-14 06:46:12

标签: iphone objective-c ios xcode

我正在创建一个类似于赛车的应用程序,我需要知道当我略微转向ipad时如何移动uiview。即,如果我将ipad转向右侧,则视图必须根据设备运动向右移动。我用了,

 -(void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if(event.subtype==UIEventSubtypeMotionShake)
{
    // Code at shake event

    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Motion" message:@"Phone Vibrate"delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];


}
}

查找设备何时被震动。我需要知道我什么时候稍微转动ipad。

1 个答案:

答案 0 :(得分:-1)

-(BOOL) canBecomeFirstResponder {

return YES;

}

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

   if(event.subtype == UIEventSubtypeMotionShake)            
  {

    // YOUR STUFF

  }

}

只需编写上面的摇动手势代码就可以了......

让我知道它是否有效!!!!

快乐编码...... !!!

相关问题