【发布时间】:2018-01-19 13:29:50
【问题描述】:
我使用了collectionView,并且还在我的 ViewController(命名为:“DashboardViewController”)中实现了拉取同步(pull_Down_To_Get_Data_From_Server)。我试过摇晃手势
我的DashboardViewController 中的代码(如下所示)并且它不工作,但类似的代码在同一应用程序的另一个viewController 中工作。
我第一次尝试在viewDidLoad 中使用canBecomeFirstResponder,第二次在viewDidAppear 中使用,但它也没有用。
要求: 实际上我想知道“.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")
}
}
【问题讨论】:
-
您的代码似乎是从stackoverflow.com/a/43151351/1226963复制的
-
实际上这段代码是用来获取摇动手势动作的,我用它是为了我自己的缘故,你使用这段代码给出的参考是为了他的目的。代码可能相似,因为它是供使用的,但不同之处在于我们使用它的方法@rmaddy
标签: ios iphone swift uigesturerecognizer handshake