gpt4 book ai didi

ios - View 内从一个 VC 到另一个 VC 的自定义转换

转载 作者:行者123 更新时间:2023-11-30 14:15:13 25 4
gpt4 key购买 nike

我有这段代码,可以将 View (containerView)内的一个 VC 更改为另一个 VC。该代码有效,但如何设置两个 View 之间的转换?

var childVC: UIViewController?
@IBOutlet weak var containerView: UIView!

func ChangeViewController() {
childVC?.willMoveToParentViewController(nil)
childVC?.view.removeFromSuperview()
childVC?.removeFromParentViewController()
childVC = storyboard?.instantiateViewControllerWithIdentifier("identifier") as? UIViewController
if let childVC = childVC {
addChildViewController(childVC)
childVC.view.frame = containerView.bounds
containerView.addSubview(childVC.view)
childVC.didMoveToParentViewController(self)
}
}

我尝试过,但没有成功:

let oldView = childVC?.view
UIView.transitionFromView(oldView!, toView: childVC.view, duration: 2, options: UIViewAnimationOptions.TransitionFlipFromLeft, completion: { (succeed) -> Void in

})

最佳答案

要在 VC 之间进行转换,您可以在 View 中显示每个 VC,并以动画方式将它们移入和移出容器 View 的 View 。大致如下:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self.containerView];

// Your animations here

[UIView commitAnimations];

关于ios - View 内从一个 VC 到另一个 VC 的自定义转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31276365/

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