gpt4 book ai didi

ios - 未调用 UIViewControllerTransitioningDelegate 方法

转载 作者:搜寻专家 更新时间:2023-11-01 06:17:48 25 4
gpt4 key购买 nike

我正在尝试使用自定义转换实现自定义弹出窗口,但我的委托(delegate)方法根本没有被调用。这是我的过渡代表:

public final class ModalTransitioningDelegate: NSObject, UIViewControllerTransitioningDelegate {

public func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
let controller = ModalPresentationController(presentedViewController: presented, presenting: presenting)

return controller
}

public func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return ModalAnimationPresenter()
}

public func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return ModalAnimationDissmiser()
}
}

这是我的弹出 View Controller :

class StopWorkoutViewController: UIViewController {

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
commonInit()
}

func commonInit() {

let transitioner = ModalTransitioningDelegate()
modalPresentationStyle = .custom
transitioningDelegate = transitioner
}
}

这是我呈现弹出窗口的方式:

@IBAction func test(_ sender: Any) {
let popup = UIStoryboard(name: "Popups", bundle: nil).instantiateInitialViewController() as! StopWorkoutViewController
present(popup, animated: true, completion: nil)
}

这是 IB 中的 View Controller :

Popup ViewController

显示弹出窗口,但全屏显示。

最佳答案

这是错误的

 func commonInit() {

let transitioner = ModalTransitioningDelegate()
modalPresentationStyle = .custom
transitioningDelegate = transitioner
}

因为您要为 StopWorkoutViewController 的转换设置动画。您需要将转换委托(delegate)设置为

 @IBAction func test(_ sender: Any) {
let transitioner = ModalTransitioningDelegate()
let popup = UIStoryboard(name: "Popups", bundle: nil).instantiateInitialViewController() as! StopWorkoutViewController
popup.transitioningDelegate = transitioner
present(popup, animated: true, completion: nil)
}

关于ios - 未调用 UIViewControllerTransitioningDelegate 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40545679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com