gpt4 book ai didi

ios - Swift segue过渡阴影

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

我在 Storyboard中使用了一些标准转场,它们每个都具有相同的背景颜色。我遇到的问题是,当 segue 过渡接近完成时,整个框架周围会出现类似背景的暗影。

Image showing transition

它非常微弱,但足以引起问题。以前有人遇到过这个吗?

最佳答案

标准的导航 Controller 推送/弹出动画使您推送的 View 和弹出的 View 变暗。如果您不喜欢这样,您可以自定义过渡,使用仅将 View 滑入和滑出但不使任何东西变暗的动画:

// this is the view controller you are pushing from

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

navigationController?.delegate = self
}

}

// make the view controller conform to `UINavigationControllerDelegate`

extension ViewController: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return PushPopAnimator(operation: operation)
}
}

// The animation controller

class PushPopAnimator: NSObject, UIViewControllerAnimatedTransitioning {
let operation: UINavigationControllerOperation

init(operation: UINavigationControllerOperation) {
self.operation = operation
super.init()
}

func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.5
}

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let from = transitionContext.viewController(forKey: .from)!
let to = transitionContext.viewController(forKey: .to)!

let rightTransform = CGAffineTransform(translationX: transitionContext.containerView.bounds.size.width, y: 0)
if operation == .push {
to.view.transform = rightTransform
transitionContext.containerView.addSubview(to.view)
UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: {
to.view.transform = .identity
}, completion: { finished in
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
})
} else if operation == .pop {
to.view.transform = .identity
transitionContext.containerView.insertSubview(to.view, belowSubview: from.view)
UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: {
from.view.transform = rightTransform
}, completion: { finished in
from.view.transform = .identity
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
})
}
}
}

有关使用 View Controller 自定义转换的信息,请参阅 WWDC 2013 视频 Custom Transitions Using View Controllers .

关于ios - Swift segue过渡阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42767241/

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