如何在自定义视图中禁用用户交互

问题描述 投票:12回答:4

我有一个自定义View qazxsw poi,我想禁用用户交互,但我不知道如何做到这一点。

我的想法是:

NSView

但这是错误的,不起作用。我怎样才能做到这一点,它只对用户可见,而没有别的?

objective-c macos cocoa nsview
4个回答
11
投票

NSView没有setEnabled:或setIgnoresMouseEvents:

实施[myView setEnabled:NO]; 返回the hitTest: method


4
投票

来自nil

here

2
投票

继承// // NSView-DisableSubsAdditions.m // Can Combine Icons // // Created by David Remahl on Tue Dec 25 2001. // Copyright (c) 2001 Infinity-to-the-Power-of-Infinity. All rights reserved. // #import "NSView-DisableSubsAdditions.h" @implementation NSView(DisableSubsAdditions) - (void)disableSubViews { [self setSubViewsEnabled:NO]; } - (void)enableSubViews { [self setSubViewsEnabled:YES]; } - (void)setSubViewsEnabled:(BOOL)enabled { NSView* currentView = NULL; NSEnumerator* viewEnumerator = [[self subviews] objectEnumerator]; while( currentView = [viewEnumerator nextObject] ) { if( [currentView respondsToSelector:@selector(setEnabled:)] ) { [(NSControl*)currentView setEnabled:enabled]; } [currentView setSubViewsEnabled:enabled]; [currentView display]; } } @end 并添加以下方法

NSView

0
投票

以下是Swift 4中的示例。将您的视图放入此自定义视图中。

-(void)mouseDown:(NSEvent *)theEvent
{

}
© www.soinside.com 2019 - 2024. All rights reserved.