我有一个自定义View qazxsw poi,我想禁用用户交互,但我不知道如何做到这一点。
我的想法是:
NSView
但这是错误的,不起作用。我怎样才能做到这一点,它只对用户可见,而没有别的?
NSView没有setEnabled:或setIgnoresMouseEvents:
实施[myView setEnabled:NO];
返回the hitTest:
method。
来自nil
:
here
继承//
// 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
以下是Swift 4中的示例。将您的视图放入此自定义视图中。
-(void)mouseDown:(NSEvent *)theEvent
{
}