在 swift 中关闭模态视图控制器(浮动面板)

Dismiss a Modal View Controller(floating panel) in swift

我正在使用这个库作为我的 floating panel

我有两个视图控制器。

  1. 主页视图控制器
  2. floatingPanel 视图控制器。

在主视图控制器中有一个日历 select 日期。当日期是 select 时,我调用 floatingPanel 视图控制器。

   func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
    log.success("date has been selected")/
       
    day = formatter.string(from: date)
   // presenting the modal view controller
       let fpc = FloatingPanelController()
       fpc.delegate = self
       
       guard let floatingPannel = storyboard?.instantiateViewController(withIdentifier: "contentPannel") as? floatingPannel else {
           return
       }
       
    fpc.set(contentViewController: floatingPannel)
    fpc.addPanel(toParent: self)
   
      
   }

加载浮动面板后,我在日历中使用 deselect 方法关闭显示的模态视图。

func calendar(_ calendar: FSCalendar, didDeselect date: Date, at monthPosition: FSCalendarMonthPosition) {
    // dismiss the current modal view
}

我想从此函数内部关闭当前模式视图。有什么办法吗

您需要将 fpc 声明为视图控制器的实例 属性。

let fpc = FloatingPanelController()

然后

 func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {

    day = formatter.string(from: date)
       
       guard let floatingPannel = storyboard?.instantiateViewController(withIdentifier: "contentPanel") as? floatingPannel else {
           return
       }
       fpc.set(contentViewController: floatingPannel)
       fpc.addPanel(toParent: self)
   }

您可以关闭来自

的视图
 func calendar(_ calendar: FSCalendar, didDeselect date: Date, at monthPosition: FSCalendarMonthPosition) {
    
    fpc.dismiss(animated: true, completion: nil)
    
}