Search code examples
iosxamarinxamarin.formsxamarin.iosz-index

Setting z-index of ScrollView on Xamarin.Forms iOS


in my Xamarin.Forms app I have a simple grid - one row is a header and second one is scrollview with content of the page. In header, I have an image with negative bottom margin (half of the image needs to be over the header and other half over scrollview).

The problem is, when I scroll this scrollview, on iOS half of my image hides behind scrollview.

I made a custom renderer and on Android setting this.TranslationZ = -100; in OnElementChanged did the job - image is over scrollview when scrolling.

On iOS I tried setting Layer.AnchorPointZ = -100;, Layer.Transform.Translate(0, 0, -100);, Layer.ZPosition = -100; in the OnElementChanged and nothing worked - my image is still hiding behind scrollview.

I couldn't find any solution over the Internet so I am asking here - what am I doing wrong? Thanks


Solution

  • In iOS renderer , have a try with LayoutSublayersOfLayer override method to check whether it works , not in OnElementChanged to modify property of Layer.

    public override void LayoutSublayersOfLayer(CALayer layer)
    {
        base.LayoutSublayersOfLayer(layer);
    
        layer.AnchorPointZ = -100;
        layer.Transform.Translate(0, 0, -100);
        layer.ZPosition = -100;
    }