ios - XLPagerTabStrip ButtonBar 粘在导航栏后面

标签 ios swift xcode xlpagertabstrip

我正在使用 XLPagerTabStrip在 swift 3 应用程序中,我使用默认的 ButtonBar 并且一切正常,但是当我像这样启用导航栏时该栏被隐藏: enter image description here

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

enter image description here

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

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
}
}

提前致谢。

最佳答案

我刚刚遇到了同样的问题。只需在 Interface Builder 中向 VC 添加一个 CollectionView,并将其类设置为“ButtonBarView”。 Here然后将其导出连接到左侧面板中的 View 。 Like this 就这样,现在 buttonBar 应该在 NavigationBar 下。

关于ios - XLPagerTabStrip ButtonBar 粘在导航栏后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40020666/

相关文章:

ios - 如何在 TableView Controller 中放置文本字段以读取内容

iOS 构建在 GitHub Actions 上失败(没有 faSTLane),但它间歇性地工作

ios - 从右下角开始 UITextView 文本,就像在计算器上一样

ios - 如何从 AppDelegate 呈现场景?

ios - Swift 如何更改 UIAlertController 的标题颜色

xcode - Xcode 中的 Storyboard 为 Controller 中的所有 View 生成不需要的 fixedFrame ="YES"

ios - 在缺少 dSYM 的 iOS 9.2 中使用 Crashlytics

ios - 需要一个 key 名称来在用于 OTP 的 twilio API 中显示发件人姓名或号码

swift - 在捕获可选值之前我是否必须解开它?

ios - ld : entry point (_main) undefined. 架构 x86_64:Xcode 9