2017-10-07 158 views
0

我已经创建了弹出窗口,其中有两个按钮。点击弹出窗口中的按钮时,我想关闭弹出窗口。如何在点击按钮时快速关闭弹出窗口?

这是我的代码: FirstViewController:

@IBAction func bar_button(_ sender: UIBarButtonItem) { 

    let vc = storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as! 
    SecondViewController 
    vc.preferredContentSize = CGSize(width: 200,height:80) 
    let navController = UINavigationController(rootViewController: vc) 
    navController.modalPresentationStyle = UIModalPresentationStyle.popover 

    let popover = navController.popoverPresentationController 
    popover?.delegate = self 
    popover?.barButtonItem = sender as! UIBarButtonItem 
    self.present(navController, animated: true, completion: nil) 

} 

SecondViewController:

@IBAction func second_button(_ sender: UIButton) { 
    //want to dismiss popover when button clicked 
     } 
@IBAction func second_button(_ sender: UIButton) { 
    //want to dismiss popover when button clicked 
     } 

回答

1

呼叫

dismiss(animated: true, completion: nil) 

这些方法里面,这将解雇提出酥料饼。

+0

但之后,它给出了这个警告 - 要求UIPopoverBackgroundVisualEffectView动画的不透明度。这将导致该效果显示中断,直到不透明度返回到1. – Abhishek

+0

@Abhishek:此问题已在下面的答案中简要解决,请看看并让我知道它是否解决您的问题,https://stackoverflow.com /问题/ 41589946/uipopoverbackgroundvisualeffectview,是幸福,问到有生命的,它的不透明度 – Bharath

相关问题