CALayer frame origin.y is flipped, 0 is at the bottom?

99封情书 提交于 2021-02-07 03:09:36

问题


When I Add a set the fram on a CALayer the origin.y is reversed, 0 is at the bottom of it super layer and increasing origin.y moves it up in its super layer. Is there something I did to cause this to be flipped? I would expect origin.y=0 to be the top, not the bottom.

Thanks,


回答1:


You can flip the coordinate system to behave like iOS like this...

layer.sublayerTransform = CATransform3DMakeScale(1.0f, -1.0f, 1.0f);



回答2:


my two cents for UIViewController and swift:

  override func viewDidLoad() {
        super.viewDidLoad()

        #if os(iOS)
        let layer = view.layer
        layer.sublayerTransform = CATransform3DMakeScale(1.0, -1.0, 1.0)
        #endif// no need under OSX. in this way we can use ONE parent controller for iOS and OSX ...
}


来源:https://stackoverflow.com/questions/5176737/calayer-frame-origin-y-is-flipped-0-is-at-the-bottom

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