我正在尝试获取一个UIViewController过渡效果,其中ViewControllerB弹出ViewContorllerA-同时仍然在后台显示ViewcontrllerA。知道我怎么能做到这一点?
过渡:
答案 0 :(得分:0)
!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。使用animate打开
UIView.animate(withDuration: 0.5, delay: 0, options: .curveLinear, animations: {
viewTemp.transform = CGAffineTransform(translationX: 0, y: -self.view.frame.height)
}) { (success: Bool) in
}
!4。使用animate关闭
UIView.animate(withDuration: 0.5, delay: 0, options: .curveLinear, animations: {
viewTemp.transform = CGAffineTransform(translationX: 0, y: self.view.frame.height)
}) { (success: Bool) in
}
答案 1 :(得分:0)
试试这个。在故事板上创建视图控制器,将类设置为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)