When working with the iOS api in Xamarin iOS you will sometimes encounter swift api’s that have been renamed or moved in Xamarin. Whilst I was recently converting a swift app to c# I encountered some interesting changes that I thought might be useful to share.
//Covered in this blog
// See this
let frame = CGRect(100, 340, 100, 100)
let originX = frame.origin.x
var originX = frame.Location.X;
Converts a rectangle in the coordinate system used for metadata outputs to one in the preview layer’s coordinate system.
Swift
let myLayer = CALayer()
let metadataRect = CGRect(x: 0, y: 0, width: 1, height: 1)
let mappedRect = myLayer.layerRectConverted(fromMetadataOutputRect: metadataRect)
C#
In Xamarin this api is called MapToLayerCoordinates
:
CALayer myLayer = new CALayer();
CGRect metadataRect new CGRect(0, 0, 1, 1);;
CGRect mappedRect = myLayer.MapToLayerCoordinates(metadataRect);