1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00

Hide the album play button when scrolling starts

This commit is contained in:
Daniel Barber 2019-02-18 13:50:47 -05:00
parent 8bc1d1e1d5
commit 86f6372dc7
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
2 changed files with 45 additions and 2 deletions

View File

@ -19,6 +19,8 @@ class AlbumViewController: NSViewController,
override func viewDidLoad() {
super.viewDidLoad()
albumScrollView.postsBoundsChangedNotifications = true
NotificationCenter.default.addObserver(
self,
selector: #selector(updateAlbums(_:)),
@ -69,5 +71,23 @@ class AlbumViewController: NSViewController,
return albumItem
}
func collectionView(_ collectionView: NSCollectionView, layout: NSCollectionViewLayout, sizeForItemAt: IndexPath) -> NSSize {
let width = collectionView.frame.size.width
var divider: CGFloat = 1
var itemWidth: CGFloat = 0
repeat {
let totalPaddingWidth = paddingWidth * 2
let totalGutterWidth = (divider - 1) * (gutterWidth + 1)
itemWidth = (width - totalPaddingWidth - totalGutterWidth) / divider
divider = divider + 1
} while itemWidth > 180
let itemHeight = itemWidth + 39
return NSSize(width: itemWidth, height: itemHeight)
}
@IBOutlet var albumScrollView: NSScrollView!
@IBOutlet var albumCollectionView: NSCollectionView!
}

View File

@ -31,15 +31,38 @@ class AlbumItemView: NSView {
addTrackingArea(trackingArea)
}
required init?(coder decoder: NSCoder) {
super.init(coder: decoder)
NotificationCenter.default.addObserver(
self,
selector: #selector(viewWillScroll(_:)),
name: NSScrollView.willStartLiveScrollNotification,
object: nil
)
}
@objc func viewWillScroll(_ notification: Notification) {
hidePlayButton()
}
override func resize(withOldSuperviewSize oldSize: NSSize) {
playButton.isHidden = true
hidePlayButton()
}
override func mouseEntered(with event: NSEvent) {
playButton.isHidden = false
showPlayButton()
}
override func mouseExited(with event: NSEvent) {
hidePlayButton()
}
func showPlayButton() {
playButton.isHidden = false
}
func hidePlayButton() {
playButton.isHidden = true
}