Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在手机晃动时调用某个功能_Ios_Xcode11_Swift5.1 - Fatal编程技术网

Ios 在手机晃动时调用某个功能

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

我正在制作一个应用程序,使用MotionBeging调用函数。 然而,当我摇动手机时,它只会调用我的函数一次,如果我停止并再次摇动手机,它会再次调用我的函数。 而我想让func激活,只要我在摇手机。 你知道我该怎么做吗?

试试这个:

Swift:

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") ;
    }
}