Just for fun .. I added this to the HomeController -
single tapping the navigation bar scrolls to the top and double tapping scrolls to the last cell or the bottom:
fileprivate func setupNavigationItems() {
let button = UIButton(type: .custom)
button.frame = CGRect(origin: .zero, size: CGSize(width: view.frame.width, height: 40))
button.setImage(#imageLiteral(resourceName: "logo2"), for: .normal)
// button.addTarget(self, action: #selector(scrollToTop(_:)), for: .touchUpInside)
let singleTap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(scrollToTop(_:)))
let doubleTap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(scrollToBottom(_:)))
singleTap.numberOfTapsRequired = 1
doubleTap.numberOfTapsRequired = 2
button.addGestureRecognizer(singleTap)
button.addGestureRecognizer(doubleTap)
singleTap.require(toFail: doubleTap)
singleTap.delaysTouchesBegan = true
doubleTap.delaysTouchesBegan = true
navigationItem.titleView = button // UIImageView(image: #imageLiteral(resourceName: "logo2"))
}
@objc func scrollToTop(_ sender: UIButton) {
collectionView?.scrollToItem(at: IndexPath(item: 0, section: 0), at: .bottom, animated: true)
}
@objc func scrollToBottom(_ sender: UIButton) {
let lastItem = collectionView(collectionView!, numberOfItemsInSection: 0) - 1
let indexPath = IndexPath(item: lastItem, section: 0)
collectionView?.scrollToItem(at: indexPath, at: .bottom, animated: true)
}
Enjoy!