尝试 segue 后呈现的 TabBarController 消失
Presented TabBarController disappearing after attempted segue
简短概要(XCode 7.2、Swift2、iOS 9.2 作为目标):
1) 在 first.storyboard 中,我有一个 viewController.
2) 在 second.storyboard 中,我有一个 tabbarController,带有多个带表 viewControllers 的导航控制器(见附图)。另外值得注意的是,当 second.storyboard 是启动时使用的那个时,一切正常。
3) 应用程序的主要 UI 在 first.storyboard 中,我想在 second.storyboard
中显示 tabbarcontroller
4) 无论我以何种方式呈现它(故事板 reference/segue、presentViewController、showViewController),tabbarcontroller 和所有初始视图都有效,但如果我点击一个 tableviewcell 以继续另一个视图,整个 tabbarcontroller 和内容都消失了,让我回到 first.storyboard 中的 viewcontroller。
我可以作弊,手动设置 rootViewController,一切似乎都有效
let sb = UIStoryboard(name: "second", bundle: nil)
let navController = sb.instantiateViewControllerWithIdentifier("secondIdentifier") as! UITabBarController
UIApplication.sharedApplication().keyWindow?.rootViewController = navController
而且我怀疑我可以为此添加动画,以使过渡不那么明显。但这似乎是我不应该做的事情,并且在将来进行故障排除时会很痛苦。我是否遗漏了一些基本的东西来完成这项工作?
编辑:它的视频不工作https://youtu.be/MIhR4TVd7CY
注意:我制作的最后一个应用最初是针对 iOS4 的,我以编程方式完成了所有视图。似乎对 IB 和 segues 等的所有更新都会使生活更易于管理(并且在大多数情况下都是如此),但这仍然是我第一次涉足它,所以我可能会遗漏一些重要的信息点描述问题。
我找到了一个更好的方法来处理这个问题:UIViewControllerTransitioningDelegate
实施起来需要一些额外的工作,但会产生 "more correct" 结果。
我的解决方案是制作一个自定义的 UIStoryboardSegue,它将执行动画并设置 rootViewController。
import UIKit
class changeRootVCSeguePushUp: UIStoryboardSegue {
override func perform() {
let applicationDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let sourceView = self.sourceViewController.view
let destinationView = self.destinationViewController.view
let sourceFrame = sourceView.frame
let destinationStartFrame = CGRect(x: 0, y: sourceFrame.height, width: sourceFrame.width, height: sourceFrame.height)
let destinationEndFrame = CGRect(x: 0, y: 0, width: sourceFrame.width, height: sourceFrame.height)
destinationView.frame = destinationStartFrame
applicationDelegate.window?.insertSubview(self.destinationViewController.view, aboveSubview: self.sourceViewController.view )
UIView.animateWithDuration(0.25, animations: {
destinationView.frame = destinationEndFrame
}, completion: {(finished: Bool) -> Void in
self.sourceViewController.view.removeFromSuperview()
applicationDelegate.window?.rootViewController = self.destinationViewController
})
}
}
除了更改 rootViewController 以使其正常工作之外,我无法在界面生成器或代码中找到其他方法。我最终会遇到各种随机导航问题,例如重叠的导航栏、在我更改选项卡之前 segue 动画无法正常工作、完全锁定且控制台中没有任何信息等。
我之前已经模态地展示了一个 tabBarcontroller(没有改变 rootviewController),但是一切都是在代码中完成的(从 ios7 和 objective-c 开始工作)。当在情节提要中创建视图层次结构时,不知道幕后发生了什么,但想知道这是否是一个错误。
感谢 Whosebug 上的其他多个答案让我找到答案!
简短概要(XCode 7.2、Swift2、iOS 9.2 作为目标):
1) 在 first.storyboard 中,我有一个 viewController.
2) 在 second.storyboard 中,我有一个 tabbarController,带有多个带表 viewControllers 的导航控制器(见附图)。另外值得注意的是,当 second.storyboard 是启动时使用的那个时,一切正常。
3) 应用程序的主要 UI 在 first.storyboard 中,我想在 second.storyboard
中显示 tabbarcontroller4) 无论我以何种方式呈现它(故事板 reference/segue、presentViewController、showViewController),tabbarcontroller 和所有初始视图都有效,但如果我点击一个 tableviewcell 以继续另一个视图,整个 tabbarcontroller 和内容都消失了,让我回到 first.storyboard 中的 viewcontroller。
我可以作弊,手动设置 rootViewController,一切似乎都有效
let sb = UIStoryboard(name: "second", bundle: nil)
let navController = sb.instantiateViewControllerWithIdentifier("secondIdentifier") as! UITabBarController
UIApplication.sharedApplication().keyWindow?.rootViewController = navController
而且我怀疑我可以为此添加动画,以使过渡不那么明显。但这似乎是我不应该做的事情,并且在将来进行故障排除时会很痛苦。我是否遗漏了一些基本的东西来完成这项工作?
编辑:它的视频不工作https://youtu.be/MIhR4TVd7CY
注意:我制作的最后一个应用最初是针对 iOS4 的,我以编程方式完成了所有视图。似乎对 IB 和 segues 等的所有更新都会使生活更易于管理(并且在大多数情况下都是如此),但这仍然是我第一次涉足它,所以我可能会遗漏一些重要的信息点描述问题。
我找到了一个更好的方法来处理这个问题:UIViewControllerTransitioningDelegate
实施起来需要一些额外的工作,但会产生 "more correct" 结果。
我的解决方案是制作一个自定义的 UIStoryboardSegue,它将执行动画并设置 rootViewController。
import UIKit
class changeRootVCSeguePushUp: UIStoryboardSegue {
override func perform() {
let applicationDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let sourceView = self.sourceViewController.view
let destinationView = self.destinationViewController.view
let sourceFrame = sourceView.frame
let destinationStartFrame = CGRect(x: 0, y: sourceFrame.height, width: sourceFrame.width, height: sourceFrame.height)
let destinationEndFrame = CGRect(x: 0, y: 0, width: sourceFrame.width, height: sourceFrame.height)
destinationView.frame = destinationStartFrame
applicationDelegate.window?.insertSubview(self.destinationViewController.view, aboveSubview: self.sourceViewController.view )
UIView.animateWithDuration(0.25, animations: {
destinationView.frame = destinationEndFrame
}, completion: {(finished: Bool) -> Void in
self.sourceViewController.view.removeFromSuperview()
applicationDelegate.window?.rootViewController = self.destinationViewController
})
}
}
除了更改 rootViewController 以使其正常工作之外,我无法在界面生成器或代码中找到其他方法。我最终会遇到各种随机导航问题,例如重叠的导航栏、在我更改选项卡之前 segue 动画无法正常工作、完全锁定且控制台中没有任何信息等。
我之前已经模态地展示了一个 tabBarcontroller(没有改变 rootviewController),但是一切都是在代码中完成的(从 ios7 和 objective-c 开始工作)。当在情节提要中创建视图层次结构时,不知道幕后发生了什么,但想知道这是否是一个错误。
感谢 Whosebug 上的其他多个答案让我找到答案!