这似乎是一件很基本的事情,但我找不到任何地方记录它:NSView的不同子类在1)添加为子视图或2)成为层支持时会以不同的方式改变它们现有的.frame
。 / p>
考虑以下代码:
func applicationDidFinishLaunching(_ aNotification: Notification) {
let cv = window.contentView!
let frame = cv.frame
let subview = <SomeSubclassOfNSView>(frame: cv.frame)
print("Subview has frame \(subview.frame)")
subview.wantsLayer = true
print("Subview has frame \(subview.frame)")
subview.frame = frame
print("Subview has frame \(subview.frame)")
subview.addSubview(tv)
print("Subview has frame \(subview.frame)")
subview.frame = frame
print("Subview has frame \(subview.frame)")
}
如果相关子视图的类型为:
NSView
,然后在整个框架中保留其框架。NSTableView
,添加为子视图时其框架重置为.zero
。NSTextView
,一旦.zero
设置为true,其框架将重置为wantsLayer
。您能指出一些解释这种现象的文档吗?我感到困惑。