Tabbar在推入UITabBarController内的ViewController时不会隐藏

时间:2017-01-29 19:06:01

标签: ios swift uiviewcontroller uinavigationcontroller uitabbarcontroller

出于这个问题的目的,我展示了我的视图层次结构的精简版本。我的应用包含UITabBarController作为基础。每个选项卡的最顶层视图控制器都是导航控制器,并且每个控制台都嵌入了视图控制器。

enter image description here

让我们选择第一个标签。

  

UITabBarController - > UINavigationController - > UITableViewController - >的UIViewController

我们假设UITableViewController实例是某种列表,UIViewController是详细视图。当用户点击列表中的项目时,它会将您带到详细信息视图。当发生这种情况时,我已将UIViewController的{​​{1}}属性设置为hidesBottomBarWhenPushed,以便当用户处于详细信息视图中时,底部的标签栏会隐藏。

enter image description here enter image description here

我的应用收到推送通知。点击它们时,它应该直接打开到详细视图中。我可以让它在那里导航。但问题是底部的标签栏仍然可见!

enter image description here

true

我在实例化视图控制器时将func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main) window = UIWindow(frame: UIScreen.main.bounds) let tabBarController = storyboard.instantiateViewController(withIdentifier: "TabBarController") as! TabBarController if openingFromPush { let firstNavigationController = storyboard.instantiateViewController(withIdentifier: "FirstNavigationController") as! UINavigationController let tableViewController = storyboard.instantiateViewController(withIdentifier: "TableViewController") as! TableViewController let viewController = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController viewController.hidesBottomBarWhenPushed = true firstNavigationController.viewControllers = [tableViewController, viewController] tabBarController.viewControllers?[0] = firstNavigationController // tabBarController.tabBar.isHidden = true window?.rootViewController = tabBarController } else { window?.rootViewController = tabBarController } window?.makeKeyAndVisible() return true } 属性设置为hidesBottomBarWhenPushed,但这似乎没有任何效果。我甚至试图像true一样直接隐藏标签栏,但这根本不做任何事情。

我无法弄清楚如何解决这个问题。任何帮助将不胜感激。

如果有帮助,我附上了一个示例Xcode项目here

1 个答案:

答案 0 :(得分:4)

您可以使用此代码推送详细视图控制器:

.ch-grid {
    margin: auto 0 0 0;
    padding: 0;
    text-align: center;
}

.ch-grid li {
    width: 12%;
    height: 220px;
    display: inline-block;
    margin: 0 auto;


}
.ch-item {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    position: relative;
    cursor: default;
    box-shadow: inset 0 0 0 16px rgba(255,255,255,0.6), 0 1px 2px rgba(0,0,0,0.1);
    transition: all 0.4s ease-in-out;
}
.ch-img-1 {
    background-image:    url(http://images.clipartpanda.com/smiley-face-clip-art-ncEepeEcA.png);
    background-size:     cover;                     
    background-repeat:   no-repeat;
    background-position: center center; 

}

.ch-img-2 {
    background-image:    url(http://i.ebayimg.com/images/a/T2eC16VHJHgE9n0yFjGLBP+DueFzkQ~~/s-l300.jpg);
    background-size:     cover;                     
    background-repeat:   no-repeat;
    background-position: center center; 
}

    .ch-img-3 {
        background-image:    url(http://images.clipartpanda.com/smiley-face-png-happy_face_Clip_Art.png);
    background-size:     cover;                     
    background-repeat:   no-repeat;
    background-position: center center; 

}
.ch-img-4 {
    background-image:    url(http://pix.iemoji.com/images/emoji/apple/ios-9/256/extraterrestrial-alien.png);
    background-size:     cover;                     
    background-repeat:   no-repeat;
    background-position: center center; 
}
.ch-info {
    position: absolute;

    width: inherit;
    height: inherit;
    border-radius: 50%;
    opacity: 0;
    transition: all 0.4s ease-in-out;
    transform: scale(0);
    -webkit-backface-visibility: hidden;
}
.ch-info h3 {
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 20px;
    margin: 0 30px;
    padding: 45px 0 0 0;
    height: 140px;
    font-family: 'Open Sans', Arial, sans-serif;
    text-shadow: 0 0 1px #fff, 0 1px 2px rgba(0,0,0,0.3);
}
.ch.info p {
    color: #fff;
    padding: 10px 5px;
    font-style: italic;
    font-size: 12px;
    border-top:1px solid rgba(255,255,255,0.5);
    opacity: 0;
    transition:all 1s ease-in-out 0.4s;
}
.ch-info p a {
    display: block;
    text-decoration: none;
    color: #fff;
    color: rgba(255,255,255,0.7);
    font-style: normal;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 9px;
    letter-spacing: 1px;
    padding-top: 4px;
    font-family: 'Open Sans', Arial, sans-serif;
}
.ch-info p a:hover {
    color: #fff222;
    color: rgba(255,242,34, 0.8);
}
.ch-item:hover .ch-info {
    transform: scale(1);
    opacity: 1;
}
ch-item:hover .ch-info p {
    opacity: 1;
    }

您不需要再次初始化导航视图控制器和表格视图控制器,它已经在标签栏控制器内