繁体   English   中英

摇动手势不起作用 iOS

[英]Shake gesture not working iOS

我使用了collectionView并在我的 ViewController(名为:“DashboardViewController”)中实现了同步拉取( pull_Down_To_Get_Data_From_Server )。 我在我的DashboardViewController尝试了摇动手势代码(如下所示),但它不起作用,但类似的代码在同一应用程序的另一个viewController中工作。

我第一次尝试在viewDidLoad中使用canBecomeFirstResponder ,然后在viewDidAppear但它也没有用。

要求:实际上我想知道“.motionShake”事件不直接触发的情况(如果有的话),我们必须以另一种方式实现? 另外我在谷歌上没有找到任何富有成果的东西。 故事板的图像可能有助于理解所有使用的实用程序

override func viewDidLoad() {
 // call super
    super.viewDidLoad()
    self.becomeFirstResponder() // for shake gesture detection
}

// it will make first responder to detect shake motion event
override var canBecomeFirstResponder: Bool {
    get {
        return true
    }
}

// get detection of shake motion event
override func motionEnded(_ motion: UIEventSubtype, with event: UIEvent?) {
    if motion == .motionShake 
    {
        print("Shake detected")
    }
}

我们在为Yoshi工作时遇到了类似的事情

我们最终在 UIWindow 上创建了一个扩展,其中包含motionBegan事件并转发该事件。 不知道是什么原因造成的,但它似乎与 swift 3.0 中断了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM