gpt4 book ai didi

iphone - Objective-C 如何有选择地禁用用户交互

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:16:49 25 4
gpt4 key购买 nike

我有一个包含许多 subview 的主视图 Controller 。我想要的是从 subview 文件中以编程方式禁用除一个 subview 及其 subview 之外的所有其他 View 。但我得到的只是所有卡住的 View 。我做错了什么?

我试过这段代码:

#define kDontDisableUserInteraction 321


- (id)initWithFrame:(CGRect)frame
{
NSLog(@"initWithFrame");
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.tag = kDontDisableUserInteraction;
}
return self;
}

-(void)something{

MVC *myController = [self getMVC];

for (UIView* subview in myController.view.subviews) {
NSLog(@"subview.tag %i", subview.tag);
if (subview.tag != kDontDisableUserInteraction){
subview.userInteractionEnabled = NO;
}
}


for (UIView *view in self.subviews){
NSLog(@"enabled!");
view.userInteractionEnabled = YES;
}
}

- (MVC *)getMVC {
Class vcc = [MVC class]; // Called here to avoid calling it iteratively unnecessarily.
UIResponder *responder = self;
while ((responder = [responder nextResponder])) if ([responder isKindOfClass: vcc]) return (MVC *)responder;
return nil;
}

最佳答案

关于iphone - Objective-C 如何有选择地禁用用户交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14196788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com