2017-09-11 66 views
0

我正在使用搖晃手勢在我的應用程序中創建新帖子。如何在啓動屏幕期間停止搖動手勢?如何在iOS中停止搖動手勢?

override func motionEnded(_ motion: UIEventSubtype, 
           with event: UIEvent?) { 
    if motion == .motionShake { 
     if self.revealtype == "opened" { 
      self.revealViewController().revealToggle(self) 
     } 

     datearray.removeAll() 

     let dateFormatter = DateFormatter() 
     dateFormatter.dateFormat = "dd-MM-yyyy" 
     let monthdate = dateFormatter.string(from: NSDate() as Date) 

     datearray.append(monthdate) 
     selectnsdate = Date() 
     print("success") 

     let ivc = self.storyboard!.instantiateViewController(withIdentifier: "selectpost") as? SelectPost 
     ivc?.shake = true 
     self.navigationController!.pushViewController(ivc!, animated: true) 
    } 
} 

回答

0

您可以在viewWillAppear上添加搖動手勢,並在viewDidDisappear viewController的方法上移除手勢。所以當你推動另一個視圖控制器時,手勢不會觸發。

0

你應該能夠簡單地通過實現你的入職視圖控制器下面吞嚥motionShake事件來實現這一目標:

override func motionEnded(_ motion: UIEventSubtype, 
         withEvent: UIEvent?) { 
    if motion != .motionShake { 
     super.motionEnded(motion, withEvent: withEvent) 
    } 
} 

(用於motionEnded文檔指出「該方法的默認實現將消息轉發響應者鏈「)。