【问题标题】:Xamarin Forms fade to hidden?Xamarin Forms 淡入隐藏?
【发布时间】:2016-04-08 23:15:43
【问题描述】:

在我当前的应用程序中,我有一堆按钮可以隐藏或显示它们对应的 stackLayout。 首先,我尝试使用 IsVisble 属性,但这会导致闪烁, 现在我在使用 LayoutTo() 也会闪烁?

我的代码如下:

async void btnStrike_Clicked(object sender, EventArgs args)
        {
            var layout = this.FindByName<StackLayout>("stkStrikeInfo");
            var rect = new Rectangle(layout.X, layout.Y, layout.Width, layout.Height - layout.Height);
            await layout.LayoutTo(rect, 2500, Easing.Linear);
        }

我想为高度设置动画!

编辑:

我找到了以下代码,它从页面中删除了 Stacklayout。 现在的问题是视图没有更新?

【问题讨论】:

    标签: xamarin xamarin.forms


    【解决方案1】:

    我认为,如果只使用一个默认动画,可以将要隐藏的布局的高度降低到零,那么你的运气会更好。

    void btnStrike_Clicked(object sender, EventArgs args)
    {
        // get reference to the layout to animate
        var layout = this.FindByName<StackLayout>("stkStrikeInfo");
    
        // setup information for animation
        Action<double> callback = input => { layout.HeightRequest = input; }; // update the height of the layout with this callback
        double startingHeight = layout.Height; // the layout's height when we begin animation
        double endingHeight = 0; // final desired height of the layout
        uint rate = 16; // pace at which aniation proceeds
        uint length = 1000; // one second animation
        Easing easing = Easing.CubicOut; // There are a couple easing types, just tried this one for effect
    
        // now start animation with all the setup information
        layout.Animate("invis", callback, startingHeight, endingHeight, rate, length, easing);
    }
    

    如果布局已经隐藏并且你想显示它,你会替换

    double startingHeight = layout.Height;
    double endingHeight = 0;
    

    double startingHeight = 0;
    double endingHeight = 55;
    

    55 只是一个任意高度,如果您希望它恢复到之前的高度,您可以在隐藏之前将之前的高度保存到一个变量中,并使用保存的高度而不是 55。

    【讨论】:

    • 您好,它给回调一个错误,“无法将 lambda 表达式分配给隐式类型变量”
    • 无法从 System.Action 转换为 Xamarin.Forms.Animation
    • 它试图使用错误的 Animate 重载,请在编辑中使用显式变量类型重试。
    • 我将如何做相反的事情?是切换开始和结束吗?
    • 对实现此解决方案的其他人的帮助说明:确保父视图已将“IsClippedToBounds”设置为 True,否则您会看到一些奇怪的行为,其中内容似乎延伸到父视图的新高度以下.
    猜你喜欢
    • 2019-04-19
    • 2016-09-29
    • 2016-12-15
    • 2019-11-06
    • 2018-12-10
    • 1970-01-01
    • 1970-01-01
    • 2017-05-04
    • 1970-01-01
    相关资源
    最近更新 更多