gpt4 book ai didi

ios - UIStoryboardSegue sourceViewController 在 destinationViewController 之上

转载 作者:搜寻专家 更新时间:2023-11-01 07:30:32 24 4
gpt4 key购买 nike

我想通过 segue 将我的 View Controller “滑出”到 destinationViewController 上方。这是我的代码:

override func perform()
{
let src = self.sourceViewController
let dst = self.destinationViewController

dst.view.superview?.insertSubview(src.view, aboveSubview: dst.view)
src.view.transform = CGAffineTransformMakeTranslation(0, 0)

UIView.animateWithDuration(0.25,
delay: 0.0,
options: UIViewAnimationOptions.CurveEaseInOut,
animations: {
src.view.transform = CGAffineTransformMakeTranslation(src.view.frame.size.width * -1, 0)
},
completion: { finished in
src.presentViewController(dst, animated: false, completion: nil)
}
)
}

幻灯片看起来不错,但是在动画期间 destinationViewController 是全黑的,当动画完成时 destinationViewController 正确显示。

如何让它在 segue 动画期间显示?

编辑:

解决了:

override func perform()
{
let src = self.sourceViewController
let dst = self.destinationViewController

src.view.superview?.insertSubview(dst.view, belowSubview: src.view)
dst.view.transform = CGAffineTransformMakeTranslation(0, 0)

UIView.animateWithDuration(0.25,
delay: 0.0,
options: UIViewAnimationOptions.CurveEaseInOut,
animations: {
src.view.transform = CGAffineTransformMakeTranslation(src.view.frame.size.width * -1, 0)
},
completion: { finished in
src.presentViewController(dst, animated: false, completion: nil)
}
)
}

最佳答案

试试这个:

class FirstCustomSegue: UIStoryboardSegue {

override func perform() {
// Assign the source and destination views to local variables.
var firstVCView = self.sourceViewController.view as UIView!
var secondVCView = self.destinationViewController.view as UIView!

// Get the screen width and height.
let screenWidth = UIScreen.mainScreen().bounds.size.width
let screenHeight = UIScreen.mainScreen().bounds.size.height

// Specify the initial position of the destination view.
secondVCView.frame = CGRectMake(screenWidth, 0.0, screenWidth, screenHeight)

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


// Animate the transition.
UIView.animateWithDuration(0.4, animations: { () -> Void in
firstVCView.frame = CGRectOffset(firstVCView.frame, -screenWidth, -0.0)
secondVCView.frame = CGRectOffset(secondVCView.frame, -screenWidth, -0.0)

}) { (Finished) -> Void in
self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController,
animated: false,
completion: nil)
}
}

}

关于ios - UIStoryboardSegue sourceViewController 在 destinationViewController 之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32693611/

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