如何在自定义视图中禁用用户互动 [英] How to disable user interaction in a custom View
本文介绍了如何在自定义视图中禁用用户互动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个自定义视图 NSView
,我想禁用用户交互,但我不知道如何这样做。
I have a custom View NSView
and I want to disable userinteraction, but I'm not sure how to do this.
我的想法是:
[myView setEnabled:NO];
但它是错误的,不工作。
but it's wrong and doesn't work. How can I make it so that, it's just visible for the user, and nothing else?
推荐答案
从此处:
//
// 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
这篇关于如何在自定义视图中禁用用户互动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文