gpt4 book ai didi

swift - 如何修复 `prepareForSegue()` 覆盖 `UIViewAnimation`

转载 作者:行者123 更新时间:2023-11-28 08:50:46 26 4
gpt4 key购买 nike

我有 MainViewController,它有堆栈 View ,它的宽度超过了屏幕的宽度。 storyboard 左侧有滑出式菜单。屏幕上有一个菜单按钮,它触发动画将 UIStackView 从 -260 更改为 0。但是当我在滑出菜单中单击某个按钮时,prepareForSegue() 立即覆盖动画和内容更改。怎么解决这个问题?

您可以在下面找到 gif。

代码如下:

 class MainViewController: UIViewController
{
var container: ContainerViewController?
@IBOutlet weak var superView: UIStackView!

@IBAction func menuButtonsChangeContent(sender: AnyObject) {
switch(sender.tag){
case 1:
container?.changeContent("first")
case 2:
container?.changeContent("second")
case 3:
container?.changeContent("third")
default:
break
}
}


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "Container"{
self.slideOutMenu("")
container = segue.destinationViewController as? ContainerViewController
}
}

@IBAction func slideOutMenu(sender: AnyObject) {

if self.superView.frame.origin.x != -260 {

UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.5, options: .CurveEaseInOut, animations: ({

self.superView.frame = CGRect(x: -260, y: 20, width: self.superView.frame.width, height: self.superView.frame.height)

}), completion: nil)
}else{
UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.5, options: .CurveEaseInOut, animations: ({
self.superView.frame = CGRect(x: 0, y: 20, width: self.superView.frame.width, height: self.superView.frame.height)

}), completion: nil)
}
}
}

//ContainerViewController.swift       
class ContainerViewController: UIViewController
{
var sourceVC: UIViewController?
var destinationVC: UIViewController?
var segueIdentifier: String?
var counter = 0

func changeContent(segueIdentifier: String)
{
self.performSegueWithIdentifier(segueIdentifier, sender: self)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.5, options: .CurveEaseInOut, animations: ({

if self.sourceVC != nil {
self.sourceVC?.view.removeFromSuperview()
print("deleted")
}

self.destinationVC = segue.destinationViewController
self.addChildViewController(self.destinationVC!)
self.destinationVC?.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
self.view.addSubview((self.destinationVC?.view)!)
self.destinationVC?.didMoveToParentViewController(self)
self.sourceVC = self.destinationVC
}), completion: nil)
}
}

和 Storyboard:

enter image description here

动图:

enter image description here

最佳答案

我在 MainViewController 中使用 UIStackView 作为 super View ,但是出现了关于阴影的问题,我将 UIStackView 更改为 UIView 。也许这很奇怪,但问题已经消失了。

enter image description here

关于swift - 如何修复 `prepareForSegue()` 覆盖 `UIViewAnimation`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34253878/

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