虽然视图是禁用mac os x,但在视图后面可访问

时间:2017-06-07 06:39:18

标签: ios objective-c macos nsview nsbutton

我在我的mac应用程序中使用LIBRARY。问题在这里就像我在viewcontroller中添加childviewcontroller作为子视图并禁用该视图虽然它是可访问的。您可以在此VIDEO中看到。

和我的STORYBOARD。您可以看到customview和view_main。

我还为NSView创建自定义类以启用和禁用它。以下是通过其accessbile禁用该视图的代码。

@implementation NSView (customview)
-(void) setEnabled:(BOOL) isEnabled{

    for (NSView* subView in self.subviews) {

        if ([subView isKindOfClass:[NSControl class]]) {

            [(NSControl*)subView setEnabled:isEnabled];
        }else  if ([subView isKindOfClass:[NSView class]]) {

            [subView setEnabled:isEnabled];
        }
    }
}

这是我点击按钮上的代码

#pragma -mark All action methods
- (IBAction)sidebarChanged:(ITSidebar *)sender {
    NSLog(@"%@: %lu", [sender selectedItem], (unsigned long)[sender selectedIndex]);
}
- (IBAction)starClicked:(id)sender {

    //[self.label setStringValue:@"Star"];
    for (NSView* v in [self.custom_view subviews]) {
        [v removeFromSuperview];
    }
    [self.view_main setEnabled:YES];
    [self.tbl_emojis setEnabled:YES];

}
- (IBAction)watchClicked:(id)sender {
    for (NSView* v in [self.custom_view subviews]) {
        [v removeFromSuperview];
    }    

    ContactUsVC* vc = [[ContactUsVC alloc] initWithNibName:@"ContactUsVC" bundle:nil];
    vc.view.frame = self.custom_view.bounds;
    [self addChildViewController:vc];
    [self.custom_view addSubview:vc.view];
    [self.view_main setEnabled:NO];
    [self.tbl_emojis setEnabled:NO];

}
- (IBAction)tagClicked:(id)sender {
    NSLog(@" Tag clicked");
    for (NSView* v in [self.custom_view subviews]) {
        [v removeFromSuperview];
    }

    HelpVC* vc = [[HelpVC alloc] initWithNibName:@"HelpVC" bundle:nil];
    vc.view.frame = self.custom_view.bounds;
    [self addChildViewController:vc];
    [self.custom_view addSubview:vc.view];
    [self.view_main setEnabled:NO];
    [self.tbl_emojis setEnabled:NO];

    //[self.label setStringValue:@"Tag"];
}
- (IBAction)trashClicked:(id)sender {
    NSLog(@" Trash clicked");
    for (NSView* v in [self.custom_view subviews]) {
        [v removeFromSuperview];
    }
    //id animator = [[ContactUsVC alloc] init];
    ChangePasswordVC* vc = [[ChangePasswordVC alloc] initWithNibName:@"ChangePasswordVC" bundle:nil];
    vc.view.frame = self.custom_view.bounds;
    [self addChildViewController:vc];
    [self.custom_view addSubview:vc.view];
    [self.view_main setEnabled:NO];
    [self.tbl_emojis setEnabled:NO];

    // [self.label setStringValue:@"Trash"];

}

我不知道为什么在我的其他视图中调用后面的按钮操作。我该怎么做才能阻止按钮操作。

请帮帮我,我被困在这里

1 个答案:

答案 0 :(得分:0)

尝试在subView的类(NSView *的子类)上实现这些方法,以避免鼠标点击流失。请注意,我不会打电话给超级!

NSView是NSResponder的子类,默认情况下,处理后的事件不会传递给响应者链。这是您示例中的超级视图。解决方案是处理事件而不是调用super。

// Avoid mouse clicks from bleeding through
- (void) mouseDown:(NSEvent*)event {}
- (void) mouseDragged:(NSEvent*)event {}
- (void) mouseUp:(NSEvent*)event {}