Comments (22)
here's my options
struct CustomPagingMenuTheme: PagingTheme {
let font: UIFont = Constants.ThemeColors.tabBarFont!
let textColor: UIColor = Constants.ThemeColors.tabBarColor
let selectedTextColor: UIColor = Constants.ThemeColors.tabBarColorActive
let backgroundColor: UIColor = .white
let headerBackgroundColor: UIColor = .white
let indicatorColor: UIColor = Constants.ThemeColors.tabBarColorActive
let borderColor: UIColor = .clear
}
struct HomePagingMenuOptions: PagingOptions {
var menuItemClass: PagingCell.Type {
return IconPagingCell.self
}
var menuItemSize: PagingMenuItemSize {
return .fixed(width: 150, height: 50)
}
var menuHorizontalAlignment: PagingMenuHorizontalAlignment {
return .center
}
var menuInteraction: PagingMenuInteraction {
return .none
}
let theme: PagingTheme = CustomPagingMenuTheme()
}
here's how I use it
override func viewDidLoad() {
super.viewDidLoad()
let first = PresetsViewController.instance()
let second = ActiveClassViewController.instance()
pagingMenuVC = FixedPagingViewController(viewControllers: [
first,
second], options: HomePagingMenuOptions())
addChildViewController(pagingMenuVC)
view.addSubview(pagingMenuVC.view)
view.constrainToEdges(pagingMenuVC.view)
pagingMenuVC.didMove(toParentViewController: self)
}
from parchment.
Hmm, seems to work just fine here. What options are you using?
from parchment.
Weird, just tried it out with exactly those options and it still works. Which version of Parchment and iOS are you using?
from parchment.
iOS 11 and i'm using the latest version. Could it be because I'm possibly using a custom tab bar controller ? where the first tab is pretty much this paging menu controller? It seems to be working when I switch to another tab (i have other tabs that are using this library, they seem to be working but not on the first tab).
from parchment.
Just tried to wrap this in a UITabBarController
, but it still works just fine. Are you doing anything else that might affect how the view is displayed?
from parchment.
Unfortunately no, that's the entire code pretty much that I posted (aside from the custom tab bar). All I do is initialize the the paging menu controller and in the child view controllers they have zero logic in them at all. Basically just a view with text in the middle.
EDIT: I can post the code of the custom tab bar if that might help
from parchment.
Sure, that might be helpful
from parchment.
Thanks for the quick replies, here's my code below for the custom tab bar maybe it is the cause of all of it, however, i'm not sure why.
class CustomTabBarController: UIViewController {
@IBOutlet weak var contentView: UIView!
@IBOutlet var tabButtons: [UIButton]!
@IBOutlet var tabActiveBorder: [UIView]!
var tabControllers: [UIViewController]!
var selectedIndex: Int = 0
class func instance()->UIViewController{
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "TabBarController")
return controller
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
tabControllers = [
HomeViewController.instance(),
StatsViewController.instance(),
ScheduleViewController.instance(),
ClassesViewController.instance(),
MoreViewController.instance()
]
setButtonSelected(button: tabButtons[selectedIndex], bar: tabActiveBorder[selectedIndex])
didPressTab(tabButtons[selectedIndex])
}
@IBAction func didPressTab(_ sender: UIButton) {
let previousIndex = selectedIndex
selectedIndex = sender.tag
setButtonUnselected(button: tabButtons[previousIndex], bar: tabActiveBorder[previousIndex])
let previousVC = tabControllers[previousIndex]
previousVC.willMove(toParentViewController: nil)
previousVC.view.removeFromSuperview()
previousVC.removeFromParentViewController()
setButtonSelected(button: sender, bar: tabActiveBorder[selectedIndex])
let currentVC = tabControllers[selectedIndex]
addChildViewController(currentVC)
currentVC.view.frame = contentView.bounds
contentView.addSubview(currentVC.view)
currentVC.didMove(toParentViewController: self)
}
func setButtonSelected(button: UIButton, bar: UIView) {
button.isSelected = true
button.tintColor = Constants.ThemeColors.bottomNavBarIconActive
button.isUserInteractionEnabled = false
bar.isHidden = false
}
func setButtonUnselected(button: UIButton, bar: UIView) {
button.isSelected = false
button.tintColor = Constants.ThemeColors.bottomNavBarIcon
button.isUserInteractionEnabled = true
bar.isHidden = true
}
}
i left out some small bits of code, but nothing related to changing views
from parchment.
When you call didPressTab:
from viewDidLoad
the contentView
bounds will be .zero
. Could it have something to do with the frame not being configured correctly? Are you setting the frame somewhere else as well?
from parchment.
That might be it, I tried moving the call to didPressTab
to viewDidAppear
instead just to see if this was the case and it was! The tabs were centered correctly but I can't put it in viewDidAppear because then the views inside that need to draw themselves will be drawn late and the user will see it being transitioned from incorrect to correct. Not sure what's the best solution here, what do you recommend? Thanks!
EDIT: After I put it in viewDidAppear I noticed that the frames for the first page changes when I go to the second page and back. But then after it changes it remains like that afterwards. Only noticed this once I moved my didPressTab
call to viewDidAppear
.
from parchment.
I would try to constrain the view using auto layout. That way the frame will be correct when the view appears, and it will also support transitioning to other sizes. Another option is to store the currently visible view as a property and set the frame in viewWillLayoutSubviews
.
from parchment.
I decided to constrain it to the edges instead like you said, seems to have worked but now for some reason the first page in the Parch page controller frame seems to be wrong and only seems to be correct when I leave the page and come back. I printed out the frame of the page in viewDidAppear
to ensure that I was properly getting the frame and I got (750.0, 0.0, 375.0, 667.0)
and then after I went to another tab and came back i got (0.0, 0.0, 375.0, 503.0)
. So all views that in that first page are not properly set because of the different frame. Why is it a different frame randomly?
EDIT: off-topic but is there a way you can change which tab is currently selected?
from parchment.
Is it one of the views inside FixedPagingViewController
or pagingMenuVC.view
that has the wrong frame? And are the initial menu items layout out correctly now?
You can select other items by calling selectPagingItem:
with the item that you want to select. The items are available in the items
property on FixedPagingViewController
. Let's say you want to select the last one you could do:
if let lastItem = pagingMenuVC.items.last {
pagingMenuVC.selectPagingItem(lastItem)
}
from parchment.
One of the views inside of FixedPagingViewController
to be more specific here is my code once again that shows how I initialize
let first = PresetsViewController.instance()
let second = ActiveClassViewController.instance()
pagingMenuVC = FixedPagingViewController(viewControllers: [
first,
second], options: HomePagingMenuOptions())
addChildViewController(pagingMenuVC)
containerView.addSubview(pagingMenuVC.view)
containerView.constrainToEdges(pagingMenuVC.view)
pagingMenuVC.didMove(toParentViewController: self)
inside of PresetsViewController
I print out the frame in viewDidAppear
and the frame is incorrect initially
also thanks for the code for switching to another item! Appreciate it a lot
from parchment.
Hmm, that's odd. Is the view for pagingMenuVC.view
correct?
from parchment.
Not sure, how would I go about making sure that it's correct?
from parchment.
You can just print out pagingMenuVC.view.frame
like you did with the other views. Just curious to see if the FixedPagingViewController
itself is displayed correctly.
from parchment.
I printed out the frame in viewDidAppear
in the view controller I initialized it in and I got (0.0, 0.0, 375.0, 553.0)
it seems to be correct. the viewDidAppear
for PresetsViewController
runs before the viewDidAppear
where I print out the frames of pagingMenuVC
. Not sure if that helps or not
from parchment.
Sorry, I'm struggling to get this reproduced and it's not really obvious to me what would cause this. Are you doing anything inside PresetsViewController
?
from parchment.
I was finally able to fix it. I initialized it in viewWillLayoutSubviews
instead of viewDidLoad
and viewDidAppear
. It's working perfectly now in iOS11 but for some reason it's not working in iOS9. It's having a similar weird effect where it's perfect when it's loaded but when you leave the screen and come back it's all messed up similar to the picture posted in the beginning. I made sure I dont do anything on viewDidAppear
or anything of that sort that could mess up the frames (will be testing it in iOS10 shortly)
EDIT: Works perfect for iOS11 and iOS10 seems like it's a bug with iOS9 after I moved it over to viewWillLayoutSubviews
from parchment.
Hi! Sorry for the late response. Are you still seeing the bug with iOS 9? If that's the case, are you able to create a minimal bug report that re-reproduces the issue?
from parchment.
Closing this for now, but feel free to open if you're able to reproduce this!
from parchment.
Related Issues (20)
- 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
- My app crash when tap to page item. HOT 4
- The package product 'Parchment' cannot be used as a dependency of this target because it uses unsafe build flags. HOT 3
- Lazy loading VC HOT 1
- keyboard avoidance issue HOT 1
- how to make collectionview rounded and add shadow to collectionview HOT 1
- Improve notification list pull to refresh
- outdated code error in PagingSizeCache HOT 3
- Getting Fatal error while using storyboard more than 2 . Unable to reload 3rd storyboard table view HOT 1
- please support indicator fixed width HOT 1
- Position of tableview is reset after tab change in header above menu example HOT 1
- Using UIAlertController in per Item HOT 3
- Navigation bar disappear when presented in a sheet. HOT 3
- About swiftUI PageView content scrollview automatically slides to the top HOT 2
- Menu item error when Archive HOT 3
- Privacy Manifest HOT 2
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.