gpt4 book ai didi

ios - CATransition 在过渡期间淡化黑色

转载 作者:行者123 更新时间:2023-11-28 15:44:51 25 4
gpt4 key购买 nike

我正在两个 View Controller 上执行简单的从右到左的转换。动画效果完美,正是我想要的结果。但是,由于呈现/呈现的 View Controller 淡入/淡出,我在背景中看到黑色闪光。

我的转变:

let transition = CATransition()
transition.duration = 2.25 // Slow duration to see the black.
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight
view.window!.layer.add(transition, forKey: kCATransition)
present(vc, animated: false, completion: nil)

我读到在 AppDelegate didFinishLaunchingWithOptions 中设置窗口颜色可以解决这个问题,但是,这似乎没有任何作用。 (过渡期间黑色仍然可见。)

self.window!.backgroundColor = UIColor.white

关于让两个 VC 在持续期间没有黑色闪烁的过渡有什么建议吗?谢谢。

最佳答案

我以前在 prepare(for:sender:) 中执行自定义转换时遇到过完全相同的问题。看完我设法解决了A Beginner’s Guide to Animated Custom Segues in iOS 8 .

在 Storyboard 中选择你的 segue,选择 custom 类型并应用自定义 SegueFromBottom 类:

enter image description here

这是 Swift 3 的更新代码。

import UIKit

class SegueFromBottom: UIStoryboardSegue
{
override func perform()
{
// Assign the source and destination views to local variables.
let firstVCView = self.source.view as UIView!
let secondVCView = self.destination.view as UIView!

// Get the screen width and height.
let screenWidth = UIScreen.main.bounds.size.width
let screenHeight = UIScreen.main.bounds.size.height

// Specify the initial position of the destination view.
secondVCView?.frame = CGRect(x: 0.0, y: screenHeight, width: screenWidth, height: screenHeight)

// Access the app's key window and insert the destination view above the current (source) one.
let window = UIApplication.shared.keyWindow
window?.insertSubview(secondVCView!, aboveSubview: firstVCView!)

// Animate the transition.
UIView.animate(withDuration: 0.4, animations: { () -> Void in
firstVCView?.frame = (firstVCView?.frame.offsetBy(dx: 0.0, dy: -screenHeight))!
secondVCView?.frame = (secondVCView?.frame.offsetBy(dx: 0.0, dy: -screenHeight))!
}, completion: { (Finished) -> Void in
self.source.present(self.destination as UIViewController, animated: false, completion: nil)
})
}
}

关于ios - CATransition 在过渡期间淡化黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43271730/

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