3

在我的基于选项卡的应用程序中,单击其中一个选项卡时,我想显示一个带有一些信息的模式视图控制器。 在我的应用程序委托的didSelectViewController方法中,我添加了模态视图。但它占据整个屏幕并隐藏标签栏。我不想隐藏标签栏,只是想显示弹出的模式视图,并可以解散。模态视图控制器隐藏标签栏

我该怎么做?

请帮忙。

在此先感谢。

回答

2

例如,如果secondViewController是你的第二个的TabBar第二的viewController,你应该这样做:

[secondViewController.view addSubview:theViewYouWantToShow];

4

模态视图控制器总是在iPhone上全屏显示。如果你不想隐藏标签栏,那么除了模态之外,你需要以其他方式呈现这个视图。

1

在iOS中,模态视图控制器始终处于可用的所有视图控制器都具有最高的优先级。所以你不能在你的案例中使用Modal View Controller。

如果您只是想在屏幕背景显示弹出窗口,然后只需使用UIAlertView。您可以根据您的要求添加“确定”或“取消”按钮以删除警报视图。

或者

如果你想显示与标签栏可见全貌,然后在该选项卡作为一个子视图添加视图。你可以给它一个感觉就像弹出一个视图使用变换属性。

1

您可以通过设置PresentationStyle以模态呈现它。此风格在正方形中呈现viewController,并且不占用全屏幕。

self.modalPresentationStyle = UIModalPresentationFormSheet; 

您还可以设置过渡:通过设置modalPresentationStyle.currentContext

self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
2

我能够“存在”一个新的视图控制器,超过另外,标签栏, 。

let newViewController = UIViewController() 
newViewController.view.backgroundColor = UIColor.red 
newViewController.modalPresentationStyle = .currentContext 
newViewController.modalTransitionStyle = UIModalTransitionStyle.flipHorizontal 
present(newViewController, animated: true, completion: nil) 

编辑:从更多的测试,上面可以有一些错误行为如果在newViewController提出有人换标签。

“修理”,我创建了一个“切换器” - 一个UIViewController即,我想翻转标签栏下的视图控制器之间动画:

view.addSubview(nextView) 
      UIView.transition(from: currentView, 
           to: nextView, 
           duration: 0.5, 
           options: animation, 
           completion: { (_) in 
       currentView.removeFromSuperview() 
      }) 

在这种情况下,currentView是的视图ViewControllerOne(当前可见的一个),而nextView是ViewControllerTwo(我们想要介绍的)的视图。

相关问题