Giter VIP home page Giter VIP logo

Comments (2)

rechsteiner avatar rechsteiner commented on May 24, 2024

Yeah this is definitely possible!

You basically need to move the collectionView into the navigation bar by setting the titleView property on the navigationItem, like this:

navigationItem.titleView = pagingViewController.collectionView

Then you need to set the frame of the title view. For example, if you always want it to be the same size as the navigation bar:

override func viewDidLayoutSubviews() {
  guard let navigationBar = navigationController?.navigationBar else { return } 
  navigationItem.titleView?.frame = CGRect(origin: .zero, size: navigationBar.bounds.size)
}

You also need to update constraints of the PagingView, as the default implementation will setup some auto-layout constraints that will mess the collection view. Since you're putting the menu view inside the navigation bar we basically want to remove the layout constraints for the menu view and set the page view controller to extend the entire size. To do this you need to create you own PagingView subclass, and override setupConstraints:

class CustomPagingView: PagingView {
  override func setupConstraints() {
    pageView.translatesAutoresizingMaskIntoConstraints = false
    pageView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
    pageView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
    pageView.topAnchor.constraint(equalTo: topAnchor).isActive = true
    pageView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
  }
}

Then create your own PagingViewController subclass and set your custom view:

class CustomPagingViewController: FixedPagingViewController {
  override func loadView() {
    view = CustomPagingView(
      pageView: pageViewController.view,
      collectionView: collectionView,
      options: options)
  }
}

I've also added a new navigation bar example you can take look at for the full implementation. Hope this works for you!

from parchment.

qiaqiaxian avatar qiaqiaxian commented on May 24, 2024

Thanks! It's very helpful.
I've solved my problem.
Thank you again.

from parchment.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.