How to create a Pop up view in xamarin Forms

后端 未结 2 432
刺人心
刺人心 2021-01-17 04:20

I need to create a Pop Up view that with an overlay.

I have tried with Absolute Layout to do this.

But I can not achieve navigation part here th

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-17 04:38

    The popup animation is more like scaling from bottom than translation. (Check the Popup animation in the android default popups in settings page)

    You can achieve the navigation like effect by setting Anchor and then animating Scale property of the popup view.

    You can achieve any animation of popup using the built in Xamarin animation. I have provided an example of scale from bottom right here.

    Xaml for popup

            
                
                    
            
    

    cs button click for the popup animation.

    private async void Button_Clicked(object sender, EventArgs e)
        {
            if (!this.popuplayout.IsVisible)
            {
                this.popuplayout.IsVisible = !this.popuplayout.IsVisible;
                this.popuplayout.AnchorX = 1;
                this.popuplayout.AnchorY = 1;
    
                Animation scaleAnimation = new Animation(
                    f => this.popuplayout.Scale = f,
                    0.5,
                    1,
                    Easing.SinInOut);
    
                Animation fadeAnimation = new Animation(
                    f => this.popuplayout.Opacity = f,
                    0.2,
                    1,
                    Easing.SinInOut);
    
                scaleAnimation.Commit(this.popuplayout, "popupScaleAnimation", 250);
                fadeAnimation.Commit(this.popuplayout, "popupFadeAnimation", 250);
            }
            else
            {
                await Task.WhenAny
                  (
                    this.popuplayout.FadeTo(0, 200, Easing.SinInOut)
                  );
    
                this.popuplayout.IsVisible = !this.popuplayout.IsVisible;
            }
    

    Above code UI result.

    Hope this could help you in achieving your UI.

提交回复
热议问题