我有一个主视图控制器,它有很多子视图。我想要的是从子视图文件以编程方式禁用除一个子视图及其子视图之外的所有其他视图。但我得到的只是冻结的观点。我做错了什么?
我试过这段代码:
#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;
}
答案 0 :(得分:2)
以下链接可能会有所帮助:
How to disable touch input to all views except the top-most view?
UIView -- "user interaction enabled" false on parent but true on child?
答案 1 :(得分:0)
我通过在所有其他视图上应用全屏按钮来解决它,并获得我希望在按钮上进行用户交互的一个视图。这样我就不允许用户点击除我希望用户点击某些功能的一个视图之外的任何功能。