prabhu
prabhu

Reputation: 1206

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?

Upvotes: 4

Views: 1936

Answers (2)

Giles
Giles

Reputation: 1668

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
}

Upvotes: 3

GoodSp33d
GoodSp33d

Reputation: 6282

For a regular Scroll View you can remove scrolls by setting horizontal & vertical scrolls to false value. So for a PDF view try this :

NSScrollView *enclosingScrollView = [myPdfView enclosingScrollView];
[enclosingScrollView setHasHorizontalScroller:NO];
[enclosingScrollView setHasVerticalScroller:NO];

Upvotes: 2

Related Questions