【发布时间】:2014-06-26 14:54:29
【问题描述】:
如何在 iOS 中以编程方式触发抖动事件?
我尝试了以下方法,但总是崩溃...
+ (void)shake {
NSLog(@"TEST");
UIMotionEventProxy *m = [[NSClassFromString(@"UIMotionEvent") alloc] _init];
m->_subtype = UIEventSubtypeMotionShake;
m->_shakeState = 1;
[[[UIApplication sharedApplication] keyWindow] motionBegan:UIEventSubtypeMotionShake withEvent:m];
[[[UIApplication sharedApplication] keyWindow] motionEnded:UIEventSubtypeMotionShake withEvent:m];
}
苹果在Hardware > Shake Gesture下的模拟器中做了什么?
【问题讨论】:
-
我真的不明白为什么需要这样做。如果你只需要振动,你可以试试这个:stackoverflow.com/questions/4724980/making-the-iphone-vibrate
标签: ios triggers delegates shake