Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How do i avoid AbsolutePosition is overwritten when using a customrender on IOS ?

$
0
0

Hallo.

I have 2 BoxViews, where i want the first box, to be like a showdow for the second box.

I used a AbsoluteLayout layout to accomplish this.

 AbsoluteLayout layout = new AbsoluteLayout();
                    { };

                    AbsoluteLayout.SetLayoutFlags(boxOne, AbsoluteLayoutFlags.PositionProportional);
                    AbsoluteLayout.SetLayoutBounds(boxOne, new Rectangle(0, 1, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));

                    AbsoluteLayout.SetLayoutFlags(boxTwo, AbsoluteLayoutFlags.XProportional);
                    AbsoluteLayout.SetLayoutBounds(boxTwo, new Rectangle(0.5, 1, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));

This works great, no probelms at all.

Then i wanted to put a GradientLayer a a background Color, on each box. The first box i position fine, but the next box, is not placed in the middel anymore, it seems like, the customrender i use, take the new Rectangle(0.5, x postition, and translate into pixel, how do i avoid this, so i can keep the absoluteLayout position.

CustomRender

[assembly: ExportRenderer(typeof(GradientBoxView), typeof(GradientBoxviewRender))]
namespace ChartClients.iOS
{
    public class GradientBoxviewRender : BoxRenderer
    {
        public CAGradientLayer gradientLayer;

        protected override void OnElementChanged(ElementChangedEventArgs<BoxView> e)
        {
            base.OnElementChanged(e);

            if (Element != null)
            {
                var gradientBoxView = e.NewElement as GradientBoxView;
                gradientLayer = new CAGradientLayer();
                if (gradientBoxView != null)
                {

                    gradientLayer.Frame = gradientBoxView.Bounds.ToRectangleF();
                    gradientLayer.Colors = new[] { gradientBoxView.EndColor.ToCGColor(), gradientBoxView.StartColor.ToCGColor() };
                }
                Layer.MasksToBounds = true;
                Layer.InsertSublayer(gradientLayer, 0);
            }
        }

        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            var boxView = sender as GradientBoxView;

            if (e.PropertyName == VisualElement.HeightProperty.PropertyName)
            {
                gradientLayer.Frame = boxView.Bounds.ToRectangleF();
                UpdateCornerRadius(Element as GradientBoxView);
            }

Thanks


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>