Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 禁用NSView的所有鼠标事件_Macos_Cocoa_Nsview - Fatal编程技术网

Macos 禁用NSView的所有鼠标事件

Macos 禁用NSView的所有鼠标事件,macos,cocoa,nsview,Macos,Cocoa,Nsview,如何禁用特定NSView(及其所有子视图)的所有鼠标事件 例如:在下图中, 我有一个滚动视图和一个边框视图(比如MyBorderView) 我想实现的功能是,当按下按钮时,禁用所有鼠标事件以滚动查看 我对它的修复是覆盖NSView的mouseDown和rightMouseDown事件。这似乎工作得很好,但对scroll来说失败了 简单地说,我想实现类似[\u scrollView DisableMouseeEvents] 覆盖该方法: - (void)scrollWheel:(NSEvent *

如何禁用特定NSView(及其所有子视图)的所有鼠标事件

例如:在下图中, 我有一个滚动视图和一个边框视图(比如MyBorderView)
我想实现的功能是,当按下按钮时,禁用所有鼠标事件以滚动查看

我对它的修复是覆盖NSView的mouseDown和rightMouseDown事件。这似乎工作得很好,但对scroll来说失败了

简单地说,我想实现类似[\u scrollView DisableMouseeEvents]

覆盖该方法:

- (void)scrollWheel:(NSEvent *)theEvent;
例如,您有一个布尔变量
disableEvents
,用于在滚动视图中启用或禁用事件。守则如下:

- (void)scrollWheel:(NSEvent *)theEvent
{
    // No disable events ---> disableEvents = NO
    if (!disableEvents) {
        [super scrollWheel:theEvent];
    }
}
如果设置了
disableEvents=YES
,则滚动将被禁用。另一方面,您也需要禁用滚动条,否则滚动条会移动它们:

[self setHorizontalScroller:nil];
[self setVerticalScroller:nil];
如果以后需要反转滚动条,只需写下:

NSScroller *scrollerHorizontal = [[NSScroller alloc]init];
NSScroller *scrollerVertical = [[NSScroller alloc]init];

[self setHorizontalScroller:scrollerHorizontal];
[self setVerticalScroller:scrollerVertical];
祝你好运