在Swift按钮上点击弹出窗口

时间:2018-01-22 12:25:21

标签: swift3

我想从按钮水龙头做一个弹出窗口。但当我点击我的按钮时,我的弹出窗口覆盖了我的所有页面。我的问题在哪里?

@IBAction func buttonTap(sender:UIButton){

    // get a reference to the view controller for the popover
    let popController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "popoverId")

    // set the presentation style
    popController.modalPresentationStyle = UIModalPresentationStyle.popover

    // set up the popover presentation controller
    popController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.up
    popController.popoverPresentationController?.delegate = self
    popController.popoverPresentationController?.sourceView = sender // button
    popController.popoverPresentationController?.sourceRect = sender.bounds

    // present the popover
    self.present(popController, animated: true, completion: nil)
}

1 个答案:

答案 0 :(得分:0)

我认为您需要更改modalPresentaionStyle

popController.modalPresentationStyle = .overCurrentContext