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:
parent
8bc1d1e1d5
commit
86f6372dc7
@ -19,6 +19,8 @@ class AlbumViewController: NSViewController,
|
|||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
|
albumScrollView.postsBoundsChangedNotifications = true
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(
|
NotificationCenter.default.addObserver(
|
||||||
self,
|
self,
|
||||||
selector: #selector(updateAlbums(_:)),
|
selector: #selector(updateAlbums(_:)),
|
||||||
@ -69,5 +71,23 @@ class AlbumViewController: NSViewController,
|
|||||||
return albumItem
|
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!
|
@IBOutlet var albumCollectionView: NSCollectionView!
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,15 +31,38 @@ class AlbumItemView: NSView {
|
|||||||
addTrackingArea(trackingArea)
|
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) {
|
override func resize(withOldSuperviewSize oldSize: NSSize) {
|
||||||
playButton.isHidden = true
|
hidePlayButton()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func mouseEntered(with event: NSEvent) {
|
override func mouseEntered(with event: NSEvent) {
|
||||||
playButton.isHidden = false
|
showPlayButton()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func mouseExited(with event: NSEvent) {
|
override func mouseExited(with event: NSEvent) {
|
||||||
|
hidePlayButton()
|
||||||
|
}
|
||||||
|
|
||||||
|
func showPlayButton() {
|
||||||
|
playButton.isHidden = false
|
||||||
|
}
|
||||||
|
|
||||||
|
func hidePlayButton() {
|
||||||
playButton.isHidden = true
|
playButton.isHidden = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user