如何以编程方式触发 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
?
尝试更换
UIMotionEventProxy *m = [[NSClassFromString(@"UIMotionEvent") alloc] _init];
with
UIMotionEventProxy *m = [[UIMotionEventProxy alloc] _init];
我想当它是令人崩溃的NSClassFromString(@"UIMotionEvent")
返回零。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)