【问题标题】:How to pop-over a UIViewController如何弹出 UIViewController
【发布时间】:2018-05-22 02:14:06
【问题描述】:

我正在尝试获得 UIViewController 过渡效果,其中 ViewControllerB 在 ViewContorllerA 上弹出,同时仍然在后台显示 ViewcontrllerA。知道我怎么能做到这一点吗?

过渡:

【问题讨论】:

    标签: ios user-interface uiviewcontroller transitions uiviewanimationtransition


    【解决方案1】:

    !1.创建一个uiview

    @IBOutlet weak var viewTemp: UIView!
    

    !2.定位

    let theScreenWidth = self.view.frame.size.width
    let theScreenHeight = self.view.frame.height
    viewTemp.frame = CGRect(x: 0, y: theScreenHeight+64, width: theScreenWidth, height: theScreenHeight-64)
    

    !3.使用动画打开

    UIView.animate(withDuration: 0.5, delay: 0, options: .curveLinear, animations: {
        viewTemp.transform = CGAffineTransform(translationX: 0, y: -self.view.frame.height)
    }) { (success: Bool) in
    }
    

    !4.使用动画关闭

    UIView.animate(withDuration: 0.5, delay: 0, options: .curveLinear, animations: {
        viewTemp.transform = CGAffineTransform(translationX: 0, y: self.view.frame.height)
    }) { (success: Bool) in
    }
    

    【讨论】:

      【解决方案2】:

      试试这个。在情节提要上创建一个视图控制器,将类设置为 CustomDialog。将视图添加到此视图控制器,这将是您在弹出窗口中想要的。如果您希望对话框丢失,请调用 confirmBlock() 或 cancelBlock()。

      //自定义对话框类

      import Foundation
      
      class CustomDialog: UIViewController, UIGestureRecognizerDelegate {
      
          var confirmBlock: ((_ result: AnyObject) -> ())?
          var cancelBlock: (() -> ())?
      
          required init?(coder aDecoder: NSCoder) {
              super.init(coder: aDecoder)
      
              definesPresentationContext = true
              providesPresentationContextTransitionStyle = true
              modalPresentationStyle = .overFullScreen
              modalTransitionStyle = .crossDissolve
          }
      
          override func viewDidLoad() {
              super.viewDidLoad()
      
              makeBlurBackground()
              let tapDismiss = UITapGestureRecognizer(target: self, action: #selector(BaseCustomDialog.tapOutside))
              tapDismiss.delegate = self
              view.addGestureRecognizer(tapDismiss)
              view.tag = GestureRecognizerUniqueTag
          }
      
          @objc fileprivate func tapOutside() {
              cancelAction()
          }
      
          func makeBlurBackground() {
              let effectView = UIView(frame: self.frame)
              effectView.backgroundColor = ClickUpConstants.defaultTransparentBackgroundColor
              effectView.isUserInteractionEnabled = false
      
              view.addSubview(effectView)
              view.sendSubview(toBack: effectView)
      
          }
      
          func confirmAction(_ result: AnyObject) {
          confirmBlock?(result)
              cleanupAndDismiss()
          }
      
          func cancelAction() {
              cancelBlock?()
              cleanupAndDismiss()
          }
      
          fileprivate func cleanupAndDismiss() {
              self.view.endEditing(true)
      
              dismiss(animated: true) { () -> Void in
                  self.confirmBlock = nil
                  self.cancelBlock = nil
              }
          }
      }
      

      如何调用对话框(即:按下按钮时)

      let dialog = UIStoryboard(name: "CustomDialogs", bundle: nil).instantiateViewController(withIdentifier: customDialog") as! CustomDialog
      let navigationController = UINavigationController(rootViewController: dialog)
      navigationController.isNavigationBarHidden = true
      
      
      dialog.cancelBlock = {
          //do something when cancel
          dialog.dismiss(animated: true, completion: nil)
      }
      
      dialog.confirmBlock = {
      //do something when cancel
          dialog.dismiss(animated: true, completion: nil)
      }
      
      self.present(navigationController, animated: true, completion: nil)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-06
        • 1970-01-01
        • 2023-04-10
        • 2018-06-13
        • 1970-01-01
        相关资源
        最近更新 更多