Comments (2)
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.
Thanks! It's very helpful.
I've solved my problem.
Thank you again.
from parchment.
Related Issues (20)
- Crash when hiding the container view which contains PagingViewController with Animation HOT 6
- SPM: Compile project error HOT 13
- Crash on iOS 12.5.4 (libswift_Concurrency.dylib (which was built for iOS 13.0)) with ver. 3.2.0 HOT 1
- Table view inside the paging viewcontroller not scrolling. HOT 3
- When hiding the animation of the select function, send crash in iPhone5s HOT 1
- Make Calender finite HOT 1
- isScrollEnabled HOT 1
- Swipe in cell does not work HOT 2
- RTL support HOT 1
- The menu items label is not showing HOT 1
- PagingIndicatorView does not fill the PagingTitleCell HOT 1
- PageView does not work in ScrollView HOT 2
- Focus position on left side HOT 1
- Issue on Index HOT 1
- Can i make the indicator fit the text length?
- There is an issue that accidentally gets stuck and cannot keep clicking other tab item HOT 2
- How To Lazy Load Page HOT 1
- How can I hide the menu? (SwiftUI)
- SwiftUI Scrolling glitch HOT 2
- Feature request: SF Icons instead of title text HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parchment.