0

所以我制作了这个功能并使用 Parchment pod

我不知何故菜单栏没有出现,但我可以水平滑动

*我使用故事板方法

这是我的代码:

import UIKit
import Parchment


 class ParchmentController: UIViewController{

override func viewDidLoad() {
    super.viewDidLoad()
    
    let storyBoardd = UIStoryboard(name: "Main", bundle: nil)
    let semua = storyBoardd.instantiateViewController(identifier: SemuaController.identfier)
    let kesehatan = storyBoardd.instantiateViewController(identifier: KesehatanController.identifier)
    let FB = storyBoardd.instantiateViewController(identifier: F_BController.identifier)
    let pelumas = storyBoardd.instantiateViewController(identifier: PelumasController.identifier)
    let bbm = storyBoardd.instantiateViewController(identifier: BbmVoucherController.identifier)
    let entertainment = storyBoardd.instantiateViewController(identifier: EntertaimentController.identfier)
    
     let vc = [
        semua,
        kesehatan,
        FB,
        pelumas,
        bbm,
        entertainment
     ]
    
    let pagingViewController = PagingViewController(viewControllers: vc)

    addChild(pagingViewController)
    view.addSubview(pagingViewController.view)
    view.constrainToEdges(pagingViewController.view)
    pagingViewController.didMove(toParent: self)
    pagingViewController.menuItemSize = .sizeToFit(minWidth: 150, height: 40)
    
  }
} 

  extension UIView {



func constrainToEdges(_ subview: UIView) {

subview.translatesAutoresizingMaskIntoConstraints = false

let topContraint = NSLayoutConstraint(
  item: subview,
  attribute: .top,
  relatedBy: .equal,
  toItem: self,
  attribute: .top,
  multiplier: 1.0,
  constant: 0)

let bottomConstraint = NSLayoutConstraint(
  item: subview,
  attribute: .bottom,
  relatedBy: .equal,
  toItem: self,
  attribute: .bottom,
  multiplier: 1.0,
  constant: 0)

let leadingContraint = NSLayoutConstraint(
  item: subview,
  attribute: .leading,
  relatedBy: .equal,
  toItem: self,
  attribute: .leading,
  multiplier: 1.0,
  constant: 0)

let trailingContraint = NSLayoutConstraint(
  item: subview,
  attribute: .trailing,
  relatedBy: .equal,
  toItem: self,
  attribute: .trailing,
  multiplier: 1.0,
  constant: 0)

addConstraints([
  topContraint,
  bottomConstraint,
  leadingContraint,
  trailingContraint])
  }
 }

当我建造它时,它是这样的

在此处输入图像描述

如您所见,顶部没有菜单栏,我仍然可以水平滑动,但我仍然可以在设置 PagingViewController 时自动设置菜单栏。

有人可以帮忙吗,以前有人用过这个吊舱吗?

谢谢

  • 是的,我知道 CollectionView 单元格的约束有点混乱
4

0 回答 0