如何禁用NSScrollView的垂直滚动?

ane*_*yzm 4 cocoa objective-c

如何禁用NSScrollView的垂直滚动?

我无法在Google上找到快速解决方案.

谢谢

Iva*_*nko 8

在NSScrollView子类中尝试此操作:

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

    if ([theEvent deltaY] != 0.0)
    {
        [[self nextResponder] scrollWheel:theEvent];
    }
}
Run Code Online (Sandbox Code Playgroud)

您也可以通过以下方式登录:

NSLog(@"user scrolled %f horizontally and %f vertically", [theEvent deltaX], [theEvent deltaY]);
Run Code Online (Sandbox Code Playgroud)


das*_*dom -1

您可以观察scrollViewDidScroll:中的内容偏移量并将x值设置为您喜欢的值。

编辑:好的,那么。你见过这个:约束滚动吗?

  • 我使用的是 mac,你给我的链接适用于 iOS (2认同)