Tips for writing a subclass of CALayer for Mac and iOS?

The y coordinate is annoying because 0 is the bottom of the mac and the top of iOS. But I do not want to flip everything., Images, for example, are the same on both platforms.

What is the most efficient way to work on both platforms?

+3
source share
1 answer

As I approached this, and the method used in the Framework Core Plot should base all my layer coordinates on a quartz coordinate system (where the origin is in the lower left corner). In iOS, I create a custom layout at the layer level that does not invert the coordinate system of the hosted layer. CALayers still have the same coordinate system in iOS, it's just that CALayers that support UIViews have their coordinate system inverted.

To do this, in the initialization of UIView, I use the following code:

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

and then I create one main hosted layer as a sublayer of this UIView support layer and add all my custom layers to this hosted level.

, , , , , .

, iOS, , NSString, .

+4

Source: https://habr.com/ru/post/1785753/


All Articles