jjochen / JJFloatingActionButton

Floating Action Button for iOS
https://jjochen.github.io/JJFloatingActionButton
MIT License
376 stars 75 forks source link

Action button items are not shown when added to custom button on center tab. #265

Closed scubax07 closed 4 years ago

scubax07 commented 4 years ago

self.tabBar.addSubview(middleBtn) middleBtn.addSubview(actionButton) actionButton.translatesAutoresizingMaskIntoConstraints = false actionButton.centerXAnchor.constraint(equalTo: middleBtn.centerXAnchor).isActive = true actionButton.centerYAnchor.constraint(equalTo: middleBtn.centerYAnchor).isActive = true self.view.layoutIfNeeded()

jjochen commented 4 years ago

This is basically a duplicate of #196. I’ll try to look into it.

scubax07 commented 4 years ago

Thanks man.

scubax07 commented 4 years ago

I was able to get a work around this issue by getting the current view controller and adding the action button to its view with necessary constraints.

guard let currentView = HelperMethods.getCurrentViewController()?.view else { return } currentView.addSubview(actionButton)

jarrillaga commented 4 years ago

@scubax07 Hey ! Can you share your code of how you solve this? I'm trying to add the button in the middle of the tabbar and I could, but the actions doesn't work and I think that you have fixed it.

scubax07 commented 4 years ago

@scubax07 Hey ! Can you share your code of how you solve this? I'm trying to add the button in the middle of the tabbar and I could, but the actions doesn't work and I think that you have fixed it.

Hi, I added the FAB button to the root controller with necessary constraints.

`

    let appDelWin = UIApplication.shared.windows.first

    guard let currentView = appDelWin?.rootViewController?.view else { return }
    currentView.addSubview(actionButton)

    actionButton.translatesAutoresizingMaskIntoConstraints = false

    actionButton.centerXAnchor.constraint(equalTo: currentView.centerXAnchor).isActive = true

    actionButton.bottomAnchor.constraint(equalTo: currentView.bottomAnchor, constant: -50).isActive = true `

I did this in my main tab controller class. Also don't forget to hide/unhide when you switch controllers as per your need. Hope this helps.