我有一个主视图 Controller ,它有许多 subview 。我想要的是通过 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;
}
最佳答案
以下链接可能会有所帮助:
How to disable touch input to all views except the top-most view?
UIView -- "user interaction enabled" false on parent but true on child?
关于iphone - Objective-C 如何有选择地禁用用户交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14196788/