Ios 在手机晃动时调用某个功能
我正在制作一个应用程序,使用MotionBeging调用函数。 然而,当我摇动手机时,它只会调用我的函数一次,如果我停止并再次摇动手机,它会再次调用我的函数。 而我想让func激活,只要我在摇手机。 你知道我该怎么做吗?试试这个: Swift:Ios 在手机晃动时调用某个功能,ios,xcode11,swift5.1,Ios,Xcode11,Swift5.1,我正在制作一个应用程序,使用MotionBeging调用函数。 然而,当我摇动手机时,它只会调用我的函数一次,如果我停止并再次摇动手机,它会再次调用我的函数。 而我想让func激活,只要我在摇手机。 你知道我该怎么做吗?试试这个: Swift: override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) { if motion == .motionShake {
override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
if motion == .motionShake {
print("Device Shaked")
}
}
目标-C
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (event.type == UIEventSubtypeMotionShake)
{
NSLog(@"Device Shaked") ;
}
}