doesnt work well with table view
piyushkantm opened this issue · 5 comments
there is no mention of compatibility with table view. Does it even support table view?
Exactly what I was wondering as well. The problem for me seems to be that the floating button does not "float".
@edwardjiang7 i found a workaround..
use UIViewController with a TableView instead of UITableViewController and it will start floating.. 😆
@piyushkantm Awesome, thanks for your super duper fast reply. I can't believe I didn't think of it! LOL! :P
Hi, here is another way to use this FAB in UITableViewController.
Simply update the position of the FAB on scrolling.
Therefore you need to override the scrollViewDidScroll
function as follow.
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
let screenHeight = UIScreen.main.bounds.height
var fixedFrame = self.bottomRightButton.frame
fixedFrame.origin.y = scrollView.contentOffset.y + screenHeight - 180
self.bottomRightButton.frame = fixedFrame
}
Cheers
there is a solution for this. you can do this by disabling the Auto Layout(button.translatesAutoresizingMaskIntoConstraints = false) property of the corresponding button
for floating button:
button.translatesAutoresizingMaskIntoConstraints = false
if #available(iOS 11.0, *) {
button.rightAnchor.constraint(equalTo: tableView.safeAreaLayoutGuide.rightAnchor, constant: -10).isActive = true
button.bottomAnchor.constraint(equalTo: tableView.safeAreaLayoutGuide.bottomAnchor, constant: -10).isActive = true
} else {
button.rightAnchor.constraint(equalTo: tableView.layoutMarginsGuide.rightAnchor, constant: 0).isActive = true
button.bottomAnchor.constraint(equalTo: tableView.layoutMarginsGuide.bottomAnchor, constant: -10).isActive = true
}