我正在使用这个库 https://github.com/kciter/Floaty,我有一个标签栏,在中间我放了 Floaty 按钮 它看起来像这样:
但是浮动按钮的点击区域太大了,我无法点击右侧的标签栏项目 像这样:
代码:
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")
}
}
有什么想法吗?谢谢
答案 0 :(得分:1)
您正在使用填充,在按钮的框架与其内容之间添加空间。这就是为什么整个盒子仍然算作命中区域的原因。尝试更改按钮的位置,而不是填充。 Floaty 毕竟是 UIView 的子类。