gpt4 book ai didi

iOS:容器 View - 更改 subview Controller 时动画推送过渡

转载 作者:可可西里 更新时间:2023-11-01 05:32:53 26 4
gpt4 key购买 nike

Apple 在此 document 中讨论了如何在两个 subview Controller 之间进行容器 View Controller 转换。 .我想为 UIModalTransitionStyle 中的 UIModalTransitionStyleCoverVertical 制作一个简单的垂直向上滑动动画。但是,transitionFromViewController 只允许使用 UIViewAnimationOptions,而不是过渡样式。那么如何制作向上滑动 View 的动画呢?

奇怪的是,要在 subview Controller 之间进行转换,您不能调用类似于 UINavigationController 的简单推送方法来为转换设置动画。

最佳答案

加载 subview ,在底部屏幕下设置 origin.y 的框架。在动画 block 中将其更改为 0 后。示例:

enum Animation {
case LeftToRight
case RightToLeft
}

func animationForLoad(fromvc: UIViewController, tovc: UIViewController, with animation: Animation) {

self.addChildViewController(tovc)
self.container.addSubview(tovc.view)
self.currentVC = tovc

var endOriginx: CGFloat = 0

if animation == Animation.LeftToRight {
tovc.view.frame.origin.x = -self.view.bounds.width
endOriginx += fromvc.view.frame.width
} else {
tovc.view.frame.origin.x = self.view.bounds.width
endOriginx -= fromvc.view.frame.width
}

self.transition(from: fromvc, to: tovc, duration: 0.35, options: UIViewAnimationOptions.beginFromCurrentState, animations: {
tovc.view.frame = fromvc.view.frame
fromvc.view.frame.origin.x = endOriginx
}, completion: { (finish) in
tovc.didMove(toParentViewController: self)
fromvc.view.removeFromSuperview()
fromvc.removeFromParentViewController()
})
}

以上代码是 2 个 subview 之间的转换,带有推送和弹出水平动画。

关于iOS:容器 View - 更改 subview Controller 时动画推送过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42121539/

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