CALayer的属性isGeometryFlipped在macOS上不起作用

问题描述 投票:1回答:1

我想将NSView的几何形状更改为左上角。但是结果不正确。(PS:在iOS平台上结果正确。)

我的代码像这样,效果如下:

import Cocoa

class ViewController: NSViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.wantsLayer = true
        self.view.layer?.isGeometryFlipped = true

        let red = NSView(frame: NSRect(origin: .zero, size: CGSize(width: 400, height: 200)))
        red.wantsLayer = true
        red.layer?.backgroundColor = NSColor.red.cgColor

        let yellow = NSView(frame: NSRect(origin: .zero, size: CGSize(width: 200, height: 100)))
        yellow.wantsLayer = true
        yellow.layer?.backgroundColor = NSColor.yellow.cgColor

        red.addSubview(yellow)
        view.addSubview(red)
    }
}

enter image description here

为什么要设置View图层的属性isGeometryFlipped = true,几何形状不会改变从左下角左上角

swift macos cocoa calayer nsview
1个回答
0
投票
macOS:在左下角macOS coordinate system
© www.soinside.com 2019 - 2024. All rights reserved.