Giter VIP home page Giter VIP logo

Comments (22)

helloimtony avatar helloimtony commented on May 23, 2024 1

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.

rechsteiner avatar rechsteiner commented on May 23, 2024

Hmm, seems to work just fine here. What options are you using?

from parchment.

rechsteiner avatar rechsteiner commented on May 23, 2024

Weird, just tried it out with exactly those options and it still works. Which version of Parchment and iOS are you using?

from parchment.

helloimtony avatar helloimtony commented on May 23, 2024

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.

rechsteiner avatar rechsteiner commented on May 23, 2024

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.

helloimtony avatar helloimtony commented on May 23, 2024

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.

rechsteiner avatar rechsteiner commented on May 23, 2024

Sure, that might be helpful

from parchment.

helloimtony avatar helloimtony commented on May 23, 2024

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.

rechsteiner avatar rechsteiner commented on May 23, 2024

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.

helloimtony avatar helloimtony commented on May 23, 2024

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.

rechsteiner avatar rechsteiner commented on May 23, 2024

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.

helloimtony avatar helloimtony commented on May 23, 2024

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.

rechsteiner avatar rechsteiner commented on May 23, 2024

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.

helloimtony avatar helloimtony commented on May 23, 2024

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.

rechsteiner avatar rechsteiner commented on May 23, 2024

Hmm, that's odd. Is the view for pagingMenuVC.view correct?

from parchment.

helloimtony avatar helloimtony commented on May 23, 2024

Not sure, how would I go about making sure that it's correct?

from parchment.

rechsteiner avatar rechsteiner commented on May 23, 2024

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.

helloimtony avatar helloimtony commented on May 23, 2024

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.

rechsteiner avatar rechsteiner commented on May 23, 2024

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.

TonyPNguyen avatar TonyPNguyen commented on May 23, 2024

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.

rechsteiner avatar rechsteiner commented on May 23, 2024

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.

rechsteiner avatar rechsteiner commented on May 23, 2024

Closing this for now, but feel free to open if you're able to reproduce this!

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.