ios - 摇动手势不适用于 iOS

标签 ios iphone swift uigesturerecognizer handshake

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

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

要求: 实际上我想知道“.motionShake”事件没有直接触发的情况(如果有的话),我们必须以另一种方式实现?另外,我没有发现任何有成果的东西 在谷歌上。 Image of storyboard may help in understanding all the utilities used

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 决裂了。

关于ios - 摇动手势不适用于 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45628271/

相关文章:

iphone - 适用于 iOS 的饼图(径向)菜单

iphone - 如何在 iPhone 的 ImageView 中加载 url 图像

ios - 我希望 collectionview 单元格上有事件指示器,直到从网络服务器加载图像

ios - Swift 中 private 关键字的使用及其在协议(protocol)中的使用?

c# - 在 Xamarin for iOS 中为 Imagebutton 设置图像

ios - Cocoapods 与 github fork 项目

ios - 加减法uitextfield

c# - 如何在 Xamarin.iOS 中播放 iOS SystemSound SoundID

swift - 错误域=NSOSStatusErrorDomain 代码=-5000 在 Swift 上使用 setResourceValue

swift - 在 Swift 4.2 中 - 如何在移动后保持 Sprite 大小(toParent : newParent)