Browse Source

Update ParentPanelController+ModernSlider.swift

pull/101/head
Abhishek 3 years ago
parent
commit
5f7aa1f262
  1. 23
      Clocker/Panel/ParentPanelController+ModernSlider.swift

23
Clocker/Panel/ParentPanelController+ModernSlider.swift

@ -16,8 +16,29 @@ extension ParentPanelController: NSCollectionViewDataSource {
}
extension ParentPanelController {
@IBAction func goForward(_: NSButton) {
navigateModernSliderToSpecificIndex(1)
}
@IBAction func goBackward(_: NSButton) {
navigateModernSliderToSpecificIndex(-1)
}
private func navigateModernSliderToSpecificIndex(_ index: Int) {
let contentView = modernSlider.superview as! NSClipView
let changedOrigin = contentView.documentVisibleRect.origin
let newPoint = NSPoint(x: changedOrigin.x + contentView.frame.width / 2, y: changedOrigin.y)
if let indexPath = modernSlider.indexPathForItem(at: newPoint) {
let previousIndexPath = IndexPath(item: indexPath.item + index, section: indexPath.section)
modernSlider.scrollToItems(at: Set([previousIndexPath]), scrollPosition: .centeredHorizontally)
}
}
@objc func collectionViewDidScroll(_ notification: NSNotification) {
let contentView = notification.object as! NSClipView
guard let contentView = notification.object as? NSClipView else {
return
}
let changedOrigin = contentView.documentVisibleRect.origin
let newPoint = NSPoint(x: changedOrigin.x + contentView.frame.width / 2, y: changedOrigin.y)
let indexPath = modernSlider.indexPathForItem(at: newPoint)

Loading…
Cancel
Save