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

标签 iphone objective-c ios

我有一个主视图 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;
}

最佳答案

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

相关文章:

ios - CollectionViewController,我应该使用普通的 UIViewController 子类化或实现它的委托(delegate)/数据源吗?

iphone - 有没有一种方法可以对 NSString 进行排序?

ios - 存储本地玩家高分的最佳方式是什么

ios - 火力地堡 : Facebook authentification with Firebase token not working

objective-c - 在我的模型中声明一个数组以在控件中使用

ViewDidLoad 中的 iphone 设备当前方向

iphone - 应用程序加载器错误 (iPhone)

iphone - 有什么办法只能通过蓝牙连接GKSession吗?

ios - iOS 中 Facebook 可标记好友 ID 的解密代码

iphone - 通过 POP UP 操作按钮 (UIAlertAction) 查看 Controller 导航/转换