0

I am using this library https://github.com/kciter/Floaty, I have a tab bar and in the middle I put the Floaty button It looks like this:

enter image description here

However the hit area of the floaty button is way too big that I cannot tap the tab bar items on the right Like this:

enter image description here

Code:

import UIKit
import Floaty

class TabBarController: UITabBarController, FloatyDelegate {

var floaty = Floaty()

override func viewDidLoad() {
    super.viewDidLoad()
    
    layoutFAB()
    //floaty.addDragging()
}

@IBAction func endEditing() {
    view.endEditing(true)
}


func layoutFAB() {
    let item = FloatyItem()
    item.hasShadow = false
    item.buttonColor = UIColor.blue
    item.circleShadowColor = UIColor.red
    item.titleShadowColor = UIColor.blue
    item.titleLabelPosition = .right
    item.title = "titlePosition right"
    item.handler = { item in
        
    }
    
    floaty.hasShadow = false
    floaty.addItem(title: "I got a title")
    floaty.addItem("I got a icon", icon: UIImage(named: "icShare"))
    floaty.addItem("I got a handler", icon: UIImage(named: "icMap")) { item in
        let alert = UIAlertController(title: "Hey", message: "I'm hungry...", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "Me too", style: .default, handler: nil))
        self.present(alert, animated: true, completion: nil)
    }
    floaty.addItem(item: item)
    floaty.paddingX = self.view.frame.width/2 - floaty.frame.width/2
    floaty.paddingY = 44
    floaty.buttonColor = #colorLiteral(red: 0.986409843, green: 0.4042935669, blue: 0.4366002679, alpha: 1)
    floaty.plusColor = .white
    floaty.fabDelegate = self
    floaty.backgroundColor = .red
    
    self.view.addSubview(floaty)
    
}

// MARK: - Floaty Delegate Methods
func floatyWillOpen(_ floaty: Floaty) {
    print("Floaty Will Open")
}

func floatyDidOpen(_ floaty: Floaty) {
    print("Floaty Did Open")
}

func floatyWillClose(_ floaty: Floaty) {
    print("Floaty Will Close")
}

func floatyDidClose(_ floaty: Floaty) {
    print("Floaty Did Close")
}
}

Any thoughts please? Thank you

mohamad
  • 39
  • 7

1 Answers1

1

You are using padding, adding space between frame of the button and its content. This is why the whole box is still counts as hit area. Try changing the position of the button, not padding. Floaty is a UIView subclass after all.

Alex Pyroh
  • 11
  • 1
  • Thank you for your comment, can you try to elaborate more please? The thing is floaty is created programmatically, not in storyboard where i could have set constraints – mohamad Apr 17 '21 at 22:34
  • @mohamad, you can do constraints and all in code and there are many ways you can accomplish it. There is a good answer with lots of options [here](https://stackoverflow.com/questions/26180822/how-to-add-constraints-programmatically-using-swift) – Alex Pyroh Apr 18 '21 at 08:21