0

so i making this feature and im using Parchment pod

and i somehow the menu bar doesnt show up, but i can swipe horizontally

*im using storyboard method

this is my code :

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

and when i build it came up like this

enter image description here

as you can see theres no menu bar on top, i can still swipe horizontally but still i though when i set PagingViewController it automatically setup the menu bar.

can someone help with, anyone already using this pod before?

thanks

  • yeah i know the constraint of that CollectionView cell kinda mess up
afi permana
  • 207
  • 3
  • 17
  • okay turns out i konw whats wrong, i set the constraint to high so my menu bar is hidden behind navbar, can anyone tell me how to set the constraint? – afi permana Oct 12 '20 at 11:58
  • You need to take into account `self.view.safeAreaInsets.top` maybe? I am using it, but I don't have access to that project now. You could check where your menu is by tapping on the `Debug View hierarchy` in XCode. Check this question in case you don't know how to find that: [link](https://stackoverflow.com/questions/28657634/xcode-cant-find-debug-view-hierarchy-button) – Starsky Oct 12 '20 at 12:12
  • ahh okay i try that one sir, i still doenst understand what should i do with that? – afi permana Oct 12 '20 at 12:22
  • You will understand where your `menu view` is, and if it is covered by the `navigationbar`, then most probably you need to modify the `top` constraint to account for `self.view.safeAreaInsets.top`. – Starsky Oct 12 '20 at 12:27
  • ahh youre right sir, it looks like the menu bar get hidden behind navbar, so now i just have to modify my top constraint, thanks sir – afi permana Oct 12 '20 at 12:38
  • one more thing sir, since im a sucker of setting constraint programmatically, can i just put that pagingViewController into UIView that i already set constraint from storyboard? – afi permana Oct 12 '20 at 12:41
  • Sure you can. Easiest for you would be to set the top constraint for the view in the storyboard, then make an `IBOutlet` for that top constraint and assign to it the desired height. – Starsky Oct 12 '20 at 13:50

0 Answers0