[英]CALayer's property isGeometryFlipped doesn't work on macOS
I want to change the NSView's geometry to the top-left corner.我想将 NSView 的几何形状更改为左上角。 But the result isn't correct.( PS: the result is correct on the iOS platform.)
但结果不正确。(PS:结果在iOS平台上是正确的。)
my code like this & the effect is as follows:我的代码是这样的&效果如下:
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)
}
}
Why I set the property isGeometryFlipped= true of View's layer, the geometry isn't change from bottom-left corner to the top-left corner ?为什么我设置属性isGeometryFlipped =真观的层,几何不从左下角切换到左上角?
It's because coordinate system in iOS and macOS are not the same.这是因为 iOS 和 macOS 中的坐标系不一样。 Point (x:0, y:0) in : - iOS : at the top left
Point (x:0, y:0) in : - iOS : 左上角
if you want the yellow view at the top left
of the red view,just do this:如果您想要红色视图
top left
的黄色视图,请执行以下操作:
let yellow = NSView(frame: NSRect(origin: CGPoint(x: 0, y: 400), size: CGSize(width: 200, height: 100)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.