我正在制作一个使用motionBegan调用函数的应用程序。 但是,当我摇动手机时,它只会调用一次我的功能,如果停下来再摇一摇,则会再次调用我的功能。 我想让功能活跃,只要我在摇晃手机即可。 有什么想法我该怎么办?
答案 0 :(得分:0)
尝试一下:
快捷键:
override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
if motion == .motionShake {
print("Device Shaked")
}
}
Objective-C
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (event.type == UIEventSubtypeMotionShake)
{
NSLog(@"Device Shaked") ;
}
}