我使用了 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/