0

ViewControllerBがViewControlllerA上でポップするUIViewControllerトランジションエフェクトを取得しようとしていますが、バックグラウンドでViewcontrllerAを引き続き表示しています。どのように私はこれを達成することができますか?UIViewControllerをポップオーバーする方法

変遷:

enter image description here enter image description here

答えて

0

1!。ビューを作成する

@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 
} 
0

これを試してみてください。ストーリーボード上にView Controllerを作成し、クラスをCustomDialogに設定します。このビューコントローラにビューを追加すると、ポップアップで必要なものが表示されます。ダイアログを消したいときは、confirmBlock()またはcancelBlock()を呼び出します。

// CustomDialogクラス

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) 
関連する問題