2012-03-21 127 views

回答

0

你可以觀察到的內容scrollViewDidScroll:偏移,並設置x值到你喜歡的值。

編輯: 好的,那麼。你見過這個:Constraining Scrolling

+1

我在Mac上,鏈接你給我的是針對iOS – aneuryzm 2012-03-21 08:53:09

+0

感謝向下表決... – dasdom 2012-03-21 09:26:55

+0

隨意移除 – aneuryzm 2012-03-21 09:33:54

-7

在想,如果您在

- (void)setHasVerticalScroller:(BOOL)flag; 

來到禁用垂直滾動條?

您也可以在Interface Builder中進行設置。

+5

它隱藏了滾動條,但滾動仍然可以通過手勢 – aneuryzm 2012-03-22 10:39:45

4

在NSScrollView子試試這個:

- (void)scrollWheel:(NSEvent *)theEvent 
{ 
    [super scrollWheel:theEvent]; 

    if ([theEvent deltaY] != 0.0) 
    { 
     [[self nextResponder] scrollWheel:theEvent]; 
    } 
} 

您也可以通過登錄它:

NSLog(@"user scrolled %f horizontally and %f vertically", [theEvent deltaX], [theEvent deltaY]); 
+0

太棒了!謝謝!! – Jad 2017-03-05 17:05:51

0

我喜歡上面伊萬的答案。然而,在我的特殊情況下,我有一個表視圖(垂直滾動),其中每行包含一個集合視圖(水平滾動)。

當用戶試圖向上/向下滾動時,如果鼠標懸停在某個集合視圖上,它們將無法向上或向下滾動。

要解決這個問題,我子類包含所述NSCollectionViews的NSScrollView和我overrided這種方法用下面的代碼:

override func scrollWheel(with event: NSEvent) 
{ 
    if (fabs(Double(event.deltaY)) > fabs(Double(event.deltaX))) { 
     self.nextResponder?.scrollWheel(with: event); 
    } else { 
     super.scrollWheel(with: event); 
    } 
} 

這樣,它檢查是否用戶主要是在一個方向上滾動,並處理它適當。