首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XLPagerTabStrip ButtonBar卡在导航栏后面

XLPagerTabStrip ButtonBar卡在导航栏后面
EN

Stack Overflow用户
提问于 2016-10-13 12:11:27
回答 4查看 2.8K关注 0票数 0

我在一个快速3应用程序中使用XLPagerTabStrip,我使用默认的ButtonBar,一切正常,但是当我启用这样的导航栏时,这个栏是隐藏的:

如果我隐藏导航条,它会显示如下:

我如何把它放在导航栏下面而不是它后面,因为我需要导航条就在那里?

代码语言:javascript
复制
import UIKit
import XLPagerTabStrip

class DesignersController: ButtonBarPagerTabStripViewController {

override func viewDidLoad() {

    buttonBarView.backgroundColor = .white
    settings.style.buttonBarBackgroundColor = .white
    settings.style.selectedBarBackgroundColor = UIColor(netHex: 0x4a4a4a)
    settings.style.selectedBarHeight = 1
    settings.style.buttonBarItemBackgroundColor = .white
    settings.style.buttonBarItemTitleColor = UIColor(netHex: 0x8c8c8c)

    super.viewDidLoad()
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    self.navigationController?.setNavigationBarHidden(true, animated: animated)
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    //self.navigationController?.setNavigationBarHidden(false, animated: animated)
}

var isReload = false

override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
    let child_1 = ChildExampleViewController(itemInfo: "Top")
    let child_2 = ChildExampleViewController(itemInfo: "Men")
    let child_3 = ChildExampleViewController(itemInfo: "Women")

    guard isReload else {
        return [child_1, child_2, child_3]
    }

    var childViewControllers = [child_1, child_2, child_3]

    for (index, _) in childViewControllers.enumerated(){
        let nElements = childViewControllers.count - index
        let n = (Int(arc4random()) % nElements) + index
        if n != index{
            swap(&childViewControllers[index], &childViewControllers[n])
        }
    }
    let nItems = 1 + (arc4random() % 8)
    return Array(childViewControllers.prefix(Int(nItems)))
}

override func reloadPagerTabStripView() {
    isReload = true
    if arc4random() % 2 == 0 {
        pagerBehaviour = .progressive(skipIntermediateViewControllers: arc4random() % 2 == 0, elasticIndicatorLimit: arc4random() % 2 == 0 )
    }
    else {
        pagerBehaviour = .common(skipIntermediateViewControllers: arc4random() % 2 == 0)
    }
    super.reloadPagerTabStripView()
}
}


import Foundation
import XLPagerTabStrip

class ChildExampleViewController: UIViewController, IndicatorInfoProvider {

var itemInfo: IndicatorInfo = "View"

init(itemInfo: IndicatorInfo) {
    self.itemInfo = itemInfo
    super.init(nibName: nil, bundle: nil)
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
    super.viewDidLoad()

    let label = UILabel()
    label.translatesAutoresizingMaskIntoConstraints = false
    label.text = "XLPagerTabStrip"

    view.addSubview(label)
    view.backgroundColor = .red

    view.addConstraint(NSLayoutConstraint(item: label, attribute: .centerX, relatedBy: .equal, toItem: view, attribute: .centerX, multiplier: 1, constant: 0))
    view.addConstraint(NSLayoutConstraint(item: label, attribute: .centerY, relatedBy: .equal, toItem: view, attribute: .centerY, multiplier: 1, constant: -50))
}

// MARK: - IndicatorInfoProvider

func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
    return itemInfo
}
}

提前谢谢。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2016-10-21 16:46:11

我也面临着同样的问题。只需在Interface中向VC添加一个CollectionView,并将其类设置为“ButtonBarView”。然后这里将其出口连接到左侧面板中的视图。像这样 Thats all,现在buttonBar应该在NavigationBar下。

票数 4
EN

Stack Overflow用户

发布于 2019-06-20 13:25:18

这帮助了我,并为iPhone X工作:

代码语言:javascript
复制
self.navigationController!.navigationBar.isTranslucent = false 
票数 3
EN

Stack Overflow用户

发布于 2017-06-02 01:49:36

代码语言:javascript
复制
self.edgesForExtendedLayout = []

我使用nib创建PagerViewController,并在viewDidLoad()中编写了上述代码

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40020666

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档