如何创建弹出视图?

时间:2011-07-05 12:21:21

标签: iphone uipopovercontroller

如何在xcode 4中以编程方式创建弹出视图? 我正在尝试创建一个包含webview的弹出视图我在视图中添加了一个后退按钮。我想转到按下后退按钮时调用它的上一个视图。 我该怎么办?

2 个答案:

答案 0 :(得分:3)

使用它并根据需要自定义

https://github.com/sonsongithub/PopupView

答案 1 :(得分:0)

步骤:1-在情节提要中创建新的VC,在VC中创建新的UIView。将其命名为(ViewPopupUI),然后在ViewPopupUI中声明所需的字段和属性。

步骤:2-在VC中

@IBOutlet private weak var viewPopupUI:UIView!
@IBOutlet var btnClose: UIButton!
  

override func viewDidLoad() {
    super.viewDidLoad()

   self.showViewWithAnimation()
}
  

@IBAction func btnCloseAction(_ sender: Any) {

    self.hideViewWithAnimation()
}
  

 //MARK: - Animation Method
private func showViewWithAnimation() {

    self.view.alpha = 0
    self.viewPopupUI.transform = CGAffineTransform(scaleX: 0.1, y: 0.1)

    UIView.animate(withDuration: 0.3) {
        self.viewPopupUI.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
        self.view.alpha = 1
    }
}

private func hideViewWithAnimation() {

    UIView.animate(withDuration: 0.3, animations: {

        self.viewPopupUI.transform = CGAffineTransform(scaleX: 0.1, y: 0.1)
        self.view.alpha = 0

    }, completion: {
        (value: Bool) in

        self.removeFromParent()
        self.view.removeFromSuperview()
    })
}
  

呼叫弹出窗口

let popupVC = storyboard?.instantiateViewController(withIdentifier: "SchoolEventGoingPopup_VC") as! SchoolEventGoingPopup_VC
    popupVC.strId =  self.dictEventDetails?.object(forKey: "id") as? Int
    view.addSubview(popupVC.view)
    addChildViewController(popupVC)