Change coordinate origin in UIView

后端 未结 2 1711
盖世英雄少女心
盖世英雄少女心 2021-01-21 04:21

Is it possible to change the coordinate system in a UIView so that (0,0) will be the top right hand corner?

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-21 05:03

    My answer bars the use of Interface Builder, but I know of no other way.

    After initiating the UIView, perform a CGAffineTransform as such:

    self.view.transform = CGAffineTransformMakeScale(-1, 1);
    

    Check the documentation for CGAffineTransform. You might also have to translate the view a bit, although I believe it should be good.

    The "-1" up there inverts the x coordinate system. Whenever you present a new view programmatically, it will work as you hope.

    Cheers!

提交回复
热议问题