on <...> which is already presenting <...>"-6ren"> on <...> which is already presenting <...>"-我正在构建一个应用程序,最近发现了由传统转场引起的巨大内存泄漏。因此我了解了 unwind segue。如果我简单地使用,一切都很好: @IBAction func prepareForUnw-6ren">
gpt4 book ai didi

ios - segueForUnwindingToViewController 导致 "Warning: Attempt to present <...> on <...> which is already presenting <...>"

转载 作者:行者123 更新时间:2023-11-28 07:06:53 28 4
gpt4 key购买 nike

我正在构建一个应用程序,最近发现了由传统转场引起的巨大内存泄漏。因此我了解了 unwind segue。如果我简单地使用,一切都很好:

    @IBAction func prepareForUnwindToMainFromFriends(segue: UIStoryboardSegue) {
}

内存泄漏已解决,“一切都很棒”。但是从 UI 的角度来看,这个解决方案看起来很丑陋。所以我从this website实现了这个功能.并稍作改动。

override func segueForUnwindingToViewController(toViewController: UIViewController, fromViewController: UIViewController, identifier: String?) -> UIStoryboardSegue {
return UIStoryboardSegue(identifier: identifier, source: fromViewController, destination: toViewController) {
let fromView = fromViewController.view
let toView = toViewController.view
if let containerView = fromView.superview {
let initialFrame = fromView.frame
var offscreenRect = initialFrame
var offscreenRectFinal = initialFrame
offscreenRect.origin.x += CGRectGetWidth(initialFrame)
offscreenRectFinal.origin.x -= CGRectGetWidth(initialFrame)
toView.frame = offscreenRect
containerView.addSubview(toView)
let duration: NSTimeInterval = 1.0
let delay: NSTimeInterval = 0.0
let options = UIViewAnimationOptions.CurveEaseInOut
let damping: CGFloat = 0.9
let velocity: CGFloat = 4.0
UIView.animateWithDuration(duration, delay: delay, usingSpringWithDamping: damping,
initialSpringVelocity: velocity, options: options, animations: {
toView.frame = initialFrame
fromView.frame = offscreenRectFinal

}, completion: { finished in
fromView.removeFromSuperview()
if let navController = toViewController.navigationController {
navController.popToViewController(toViewController, animated: false)
}
})
}
}
}

但现在我收到一条错误消息:

2015-05-12 08:47:31.841 PING0.4[4343:1308313] Warning: Attempt to present <NotificationViewController: 0x177030b0>  on <PING0_4.ViewController: 0x16271000> which is already presenting <NotificationViewController: 0x1a488170>

而且我在我的应用程序中被阻止了。我可以从 VC1 转到 VC2,然后回到 VC2,但之后我就不能再回到 VC1。看起来我只能使用这个 segue 一次。

有人知道发生了什么事吗?

最佳答案

使用上述过渡动画代码创建了展开转场的示例代码。结帐SampleUnwind项目将帮助您理解展开的 segue(以及它是多么简单)。

在项目中有一个导航 Controller ,里面有三个 View Controller (Home->First->second)。

在 Home Controller 中创建了展开操作,当点击第二个 Controller 的“主页”按钮时将调用该操作(简单的展开操作)。

@IBAction func unwindToHomeViewController(segue:UIStoryboardSegue) {
}

我创建了 TempNavigationController 子类 UINavigationController 并将那个 TempNavigationController 设置为 Storyboard中的导航 Controller 。您给出的上述方法在其中存在,因为根据以下引用,这将是 fromViewController 的容器。

引用:Apple有关在两个 subview Controller 之间转换的文档。

您可以将其与您的项目进行比较,也许您可​​以在您的项目中找到任何重复的(或多个/错误的)segue。

关于ios - segueForUnwindingToViewController 导致 "Warning: Attempt to present <...> on <...> which is already presenting <...>",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30196238/

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