NSSplitViewController causing contained views to draw over window corners

浪尽此生 提交于 2019-12-06 02:05:03

I have seen such problem and it seems to be real bug. But there is workaround for that. You need make sure NSSplitViewController renders itself in view which is backed by CA layer. So to do this in your project, I added man-in-the-middle view controller with container view. Then I placed your split view inside of this container view. Finally parent view of the container view is set to be layer backed. Here is the picture:

After that I can see everything fine:

On another note: make sure you dont use 1000 priority of constraints until it is really required. I normally use 750 (I fixed that as well). Otherwise you will get a lot warnings about unsatisfiable things.

Here is you fixed project: https://github.com/emankovski/splitviewroundcorrners

Make sure that root view in the view hierarchy to be layer-backed BEFORE adding it to view hierarchy.

Example. This works. Tested and confirmed to work in macOS 10.12 Sierra. Xcode 8.0.

split.view.wantsLayer = true
window.contentViewController = split
split.splitViewItems = [
    NSSplitViewItem(viewController: vc),
]

But this doesn't.

window.contentViewController = split
split.splitViewItems = [
    NSSplitViewItem(viewController: vc),
]
split.view.wantsLayer = true

I don't know what's happening here, and why this works. But let me speculate.

NSWindow without layer-backing root view just draws naively with no compositor involved. So they cannot mask out corners, and such artifacts appears. Just making them layer-backed will make it work. Just as like @Eugene pointed out.

Making everything layer-backed is not hard. Just make root view to be layer-backed, and every subviews in the hierarchy will be layer-backed to the leaf. (RTFM for details: CALayer.wantsLayer.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!