Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable scroll for PDFView inside NSCollectionView

I have a PdfView inside a CollectionView. Since both have its own scrollviews I have conflicts in scrolling. So i want to disable scrolling for PdfView. How can I do it?

like image 854
prabhu Avatar asked Oct 24 '25 03:10

prabhu


1 Answers

My solution is a little rough, but does work. I only wanted to stop horizontal scrolling on my PDFViews - my collection view scrolls horizontally.

I made a view that selectively filters out the scroll mouse events and put it over the PFD view.

class HorizontalScrollBlockerView: NSView
{
    var scrollNextResponder: NSResponder?

    override func scrollWheel(with event: NSEvent) {
        guard scrollNextResponder != nil else {
            return
        }

        if fabs(event.deltaX) >= fabs(event.deltaY) {
            scrollNextResponder!.scrollWheel(with: event)
        } else {
            super.scrollWheel(with: event)
        }
    }
}

I set the view's 'scrollNextResponder' to be the superView of the PDFView.

I also wrote a method that gets the first child scroll view (enclosedScrollView) which makes sure the PDFView is solid in the horizontal axis when correctly scaled.

if let scrollView = pdfView.enclosedScrollView {
    scrollView.usesPredominantAxisScrolling = true
    scrollView.hasHorizontalScroller = false
    scrollView.horizontalScrollElasticity = NSScrollView.Elasticity.none
}
like image 146
Giles Avatar answered Oct 27 '25 03:10

Giles