如何获取它,以便我以前的视图不会显示在 Xcode 模拟器中的新视图后面

问题描述 投票:0回答:0

所以目前我正在编写一个应用程序,我想从一个视图转到一个新视图,但是每次我使用segue时,旧视图都会在新视图的背景中看到,就像这样。 As you can see at the top the previous view is seen behind

还应该注意的是,在模拟器上我只需向下拖动,视图就会消失,我也不希望这种情况发生。

在属性检查器的故事板上,我使用标识符:FadeSegue、类:FadeSegue、选择器:none 和种类:Custom

实现 segue 的代码如下所示: 在viewDidLoad函数中:

let cTap = UITapGestureRecognizer(target: self, action: #selector(shiftView(_:)))
view.addGestureRecognizer(cTap)

shiftView函数:

    @objc func shiftView(_ sender: UITapGestureRecognizer)
    {
        performSegue(withIdentifier: "FadeSegue", sender: nil)
    }

然后是 FadeSegue 动画代码(我很确定问题不是由此而来)

import UIKit


class FadeSegue: UIStoryboardSegue {
    override func perform() {
        let source = self.source
        let destination = self.destination

        let transition = CATransition()
        transition.type = CATransitionType.fade
        transition.duration = 0.7

        source.view.window?.layer.add(transition, forKey: kCATransition)

        source.present(destination, animated: false, completion: nil)
    }
}

如果大家发现任何问题请告诉我。

使用这段代码,我希望新视图能够通过淡入完全替换旧视图。淡入淡出动画确实有效,但您仍然可以看到新视图后面的旧视图,并且您仍然可以向下滑动以摆脱新视图。

swift xcode segue
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.