在我当前的应用程序中,我有一堆按钮可以隐藏或显示它们对应的 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。
现在的问题是 View 没有更新?
最佳答案
我认为您只需要一个默认动画就会有更好的运气,它将您想要隐藏的布局的高度降低到零。
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。
关于Xamarin Forms 淡出隐藏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36498306/