2017-06-05 71 views
0

我使用的PopupDialog库,并有一个按钮,拍了拍负载时的弹出如下图所示的代码:如何打开视图控制器时,弹出是开放的 - 迅速3

// Create the dialog 
let popup_around_me = AroundMePopUpViewController(nibName: "popup_around_me", bundle: nil) 
popup_around_me.gh = self.getJobByLatitude(latitude: marker.position.latitude) 
let popup = PopupDialog(viewController: popup_around_me, buttonAlignment: .horizontal, transitionStyle: .bounceDown, gestureDismissal: true) 

present(popup, animated: true, completion: nil) 
//print("marker.position.latitude: \(marker.position.latitude)") 

在我的弹出有是两个打开控制器的按钮。

因为我使用导航栏,我想我应该先关闭弹出窗口然后打开我的控制器。不这样做我的导航栏不加载。

但我不知道这是否是正确的做法。 如果没关系,我该怎么办(关闭弹出窗口并打开控制器)?

我的按钮功能:

func cliclOnContent(tapGestureRecognizer: UITapGestureRecognizer) 
    { 
     print("job id: \(self.gh.id)") 

//below codes not load my navigation. 
//  let vc = self.storyboard!.instantiateViewController(withIdentifier: "ContentAJobViewController") as! ContentAJobViewController 
//  vc.job_id = self.gh.id 
//  self.navigationController?.pushViewController(vc, animated: true) 

     // let storyboard = UIStoryboard(name: "Main", bundle: nil) 
//  let controller = storyboard?.instantiateViewController(withIdentifier: "ContentAJobViewController") as! ContentAJobViewController 
//  controller.job_id = self.gh.id 
//  self.present(controller, animated: true, completion: nil) 

    } 
+0

你能提供一个参考(链接)到你正在使用的'PopupDialog'吗? –

+0

https://github.com/Orderella/PopupDialog –

+0

你可以尝试使用'popup.tapButtonWithIndex'来关闭你的弹出窗口吗? –

回答

0

编辑:

其实你不必关闭它。它会自动关闭所有你需要做的就是在相应的按钮操作中调用你的视图控制器。

我有一个视图控制器,我用取消按钮中的segue这样做了一个调用。

enter image description here

而且我的输出是一样this.by我只是用他们的演示文件进行快速反应的方式。

enter image description here

+0

如何关闭弹出窗口?如何检测弹出窗口是否关闭?有没有任何功能来检测它? –

0

我不熟悉以上的生命周期中提到PopupDialog,但如果它的工作方式类似于UIAlertController当按钮动作都完成它会自动解散。

看起来您正在使用自定义PopupDialog版本。你应该实现你类似这样的按钮和按键操作:

func showCustomDialog(animated: Bool = true) { 

     // Create a custom view controller 
     let popup_around_me = AroundMePopUpViewController(nibName: "popup_around_me", bundle: nil) 


     let popup_around_me = AroundMePopUpViewController(nibName: "popup_around_me", bundle: nil) 
     popup_around_me.gh = self.getJobByLatitude(latitude: marker.position.latitude) 
     // Create the dialog 
     let popup = PopupDialog(viewController: popup_around_me, buttonAlignment: .horizontal, transitionStyle: .bounceDown, gestureDismissal: true) 


     // Create first button 
     let buttonOne = CancelButton(title: "CANCEL", height: 60) { 
      // Do what you want when you cancel 
     } 

     // Create second button 
     let buttonTwo = DefaultButton(title: "Open VC", height: 60) { 
      self.gotoMyOtherViewController() 
     } 

     // Add buttons to dialog 
     popup.addButtons([buttonOne, buttonTwo]) 

     // Present dialog 
     present(popup, animated: true, completion: nil) 
    } 
} 

通知“打开VC”按钮动作此范围内调用self.gotoMyOtherViewController()是你会因为你是在segue代替使用navigation bar打开其他VC

func gotoMyOtherViewController(){ 
    let vc = self.storyboard!.instantiateViewController(withIdentifier: "ContentAJobViewController") as! ContentAJobViewController 
    vc.job_id = self.gh.id   
    navigationController?.pushViewController(vc, animated: true) 
} 
相关问题