摇动手势不工作iOS
问题描述:
我已经使用collectionView
并在我的ViewController(名为:“DashboardViewController”)中实现了拉同步(pull_Down_To_Get_Data_From_Server)。我试过 摇号 我的DashboardViewController
中的代码(下面给出),但它不工作,但类似的代码正在另一个viewController
同一应用程序中工作。摇动手势不工作iOS
我在第一次使用时使用了canBecomeFirstResponder
,第二次使用了viewDidAppear
,但它也没用。
要求: Actualy我想知道的情况下(如果有的话),其中“.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")
}
}
看起来你的代码是从https://stackoverflow.com/a/43151351/1226963 – rmaddy
复制的其实这个代码是用来获得摇晃手势的动作,我用它为我自己和你使用这个参考代码为他的目的。代码可能相似,因为它提供了使用,但区别在于我们使用它的方法@rmaddy –