无法关闭在Interface Builder中创建的NSView实例的剪辑

时间:2021-06-02 23:31:21

I am unable to figure out how to turn off subview/sublayer clipping when my custom view is defined in Interface Builder. When I create the view programmatically, and do the setup found in many questions here on *, it works fine for both subviews added to a view, and sublayers added to view.layer. Those things are:

在Interface Builder中定义自定义视图时,我无法弄清楚如何关闭子视图/子图层剪辑。当我以编程方式创建视图,并在*上的许多问题中进行设置时,它适用于添加到视图的子视图和添加到view.layer的子图层。那些东西是:

((NSView*)containingWindow.contentView).wantsLayer = YES;
view.wantsLayer = YES;
view.layer.masksToBounds = NO;

Once these are done (in that order), everything works great for views that are created in code. If I do the same thing (or ANYTHING else, for that matter) for views created in IB, I get nowhere.

完成这些操作后(按此顺序),一切都适用于在代码中创建的视图。如果我对在IB中创建的视图做同样的事情(或者其他任何事情),我无处可去。

I have tried using a custom NSView that defines the method:

我尝试使用定义方法的自定义NSView:

- (CALayer*)makeBackingLayer {
    CALayer* layer = [CALayer layer];
    layer.masksToBounds = NO;

    return layer;
}

- (BOOL)wantsDefaultClipping {
    return NO;
}

Doesn't help. I've also tried checking the box under "Core Animation Layer" in View Effects in IB. That didn't help either. Finally, I tried turning off constraints, just in case that was responsible. Did not work either.

没有帮助。我也尝试在IB中的View Effects中的“Core Animation Layer”下选中框。这也没有帮助。最后,我试图关闭约束,以防万一是负责任的。也没用。

Any help is appreciated. One thing I notice is that my backing layer view "masksToBounds" starts out NO, the way I set it, but when I log the view hierarchy later, it has become YES on the very same view (verified by its memory address.)

任何帮助表示赞赏。我注意到的一件事是我的后备层视图“masksToBounds”以我设置它的方式开始NO,但是当我稍后记录视图层次结构时,它在同一视图上变为YES(通过其内存地址验证)。

1 个解决方案

#1


-4  

Try:

myView.wantsDefaultClipping = NO;

and do it also for child views.

并且也为儿童观点做。

#1


-4  

Try:

myView.wantsDefaultClipping = NO;

and do it also for child views.

并且也为儿童观点做。