【问题标题】:Call a function while the phone is being shaken摇晃手机时调用函数
【发布时间】:2019-11-11 09:16:34
【问题描述】:

我正在制作一个使用 motionBegan 调用函数的应用。 但是,当我摇晃手机时,它只会调用一次我的功能,然后如果我停下来再次摇晃它,它就会再次调用它。 只要我在摇晃手机,我就想让 func 处于活动状态。 有什么想法我应该怎么做?

【问题讨论】:

    标签: ios xcode11 swift5.1


    【解决方案1】:

    试试这个:

    斯威夫特:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-10
      • 2011-07-11
      • 1970-01-01
      • 2013-03-24
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多