iOS摇一摇功能方法实现

//只需要让这个Controller本身支持摇动
 
//同时让他成为第一相应者:
 
- (void)viewDidLoad
 
{
    [super viewDidLoad];
 
    [[UIApplicationsharedApplication] setApplicationSupportsShakeToEdit:YES];
 
    [selfbecomeFirstResponder];
}
 
  
 
//然后去实现那几个方法
 
- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
 
{
 
    //检测到摇动
 
}
 
  
 
- (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
 
{
 
    //摇动取消
 
}
 
  
 
- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
 
{
 
    //摇动结束
 
    if (event.subtype == UIEventSubtypeMotionShake) {
 
        //something happens
 
    }
 
}

你可能感兴趣的:(OC-方法,摇一摇)