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/

相关文章:

ios - 在 Ios 中合并两个视频

sql - '没有可用的数据库 channel '

iphone - 如何使用 UIGraphicsBeginImageContextWithOptions?

iphone - "Share Screen"iOS 6

ios - 创建数组并将元素分配给 UITableViewCell 并取回 labelText 元素时出现问题

ios - 如何去除 UIBlurEffect 产生的白色外发光

ios - iphone 如何推送浏览量?

swift - 在 Swift 中将数组传递给具有可变数量参数的函数

没有 "Optional"的 Swift 字符串/字符可选打印

swift - 使用 ARKit 显示 X3D 文件