代码:
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(shake) name:@"shake" object:nil];
if(event.type == UIEventTypeMotion && event.subtype == UIEventSubtypeMotionShake)
{
// SOMETHING HERE
}
NSLog(@"motion Began");
}
else
{
NSLog(@"Shake Is Over");
}
}
震动模式没有实现。
这段代码定义了一个motionBegan方法,该方法在设备震动时被调用。在方法中,它添加了一个观察者来监听"shake"通知,并调用shake方法。如果事件的类型是UIEventTypeMotion且子类型是UIEventSubtypeMotionShake,那么在这里应该添加震动模式的实现代码。不过,这段代码并没有实现震动模式,只是定义了一个空的if语句。