アクションをトリガーするボタンと完全に連携する ViewController があります。ボタンをシェイクイベントに置き換えたいので、グーグルで調べて、UIView から継承する ShakeDetector クラスを作成しました
私の実装は次のとおりです。
@implementation ShakeDetector
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion == UIEventSubtypeMotionShake )
{
// User was shaking the device. Post a notification named "shake".
//[[NSNotificationCenter defaultCenter] postNotificationName:@"spin" object:self];
NSLog(@"sss");
}
}
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
}
@end
しかし、私はそれを機能させることができません...何か助けはありますか?
ありがとう