C# Xamarin-动画布局

C# Xamarin-动画布局,c#,animation,xamarin,xamarin.forms,C#,Animation,Xamarin,Xamarin.forms,早上好,我尝试在单击StackPanel上的用户名时实现该功能,以便键盘不会隐藏信息。但是什么不是最好的选择呢?我正在使用iOS和Android。你能帮我吗 <?xml version="1.0" encoding="UTF-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/x

早上好,我尝试在单击StackPanel上的用户名时实现该功能,以便键盘不会隐藏信息。但是什么不是最好的选择呢?我正在使用iOS和Android。你能帮我吗

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             x:Class="BackGround.BackGroundImageDemo" BackgroundImage="Avion.jpg">
    <ContentPage.Content >
     <StackLayout VerticalOptions="Center" Padding="5, 50, 120, 0" BackgroundColor="White" HorizontalOptions="Center">
        <Entry Placeholder="UserName" PlaceholderColor="Gray" TextColor="Navy"  />
        <Entry Placeholder="Password" IsPassword="true"  PlaceholderColor="Gray" TextColor="Navy"/>
     </StackLayout>

    </ContentPage.Content>
</ContentPage>

Chase应用程序也有类似的功能

-

我从你的问题中了解到,你想要一种方法来确保当键盘弹出时,它不会覆盖屏幕上的条目和/或其他相关信息,对吗

实现这一点的方法是将您的内容放在
滚动视图中,这样用户就可以在必要时滚动它。此外,Android和iOS都会自动滚动屏幕,直到条目可见

我将您的示例更改为如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             x:Class="BackGround.BackGroundImageDemo" BackgroundImage="Avion.jpg">
    <ScrollView>
        <StackLayout VerticalOptions="Center" Padding="5, 50, 120, 0" BackgroundColor="White" HorizontalOptions="Center">
            <Entry Placeholder="UserName" PlaceholderColor="Gray" TextColor="Navy"  />
            <Entry Placeholder="Password" IsPassword="true"  PlaceholderColor="Gray" TextColor="Navy"/>
        </StackLayout>
    </ScrollView>
</ContentPage>


这通常不是在Xamarin.Forms中设置项目动画的方式。看看这本书

这是一个漂亮的应用程序,使用第三方动画库和自定义故事板XAML提供了良好的用户体验

例如,淡入控件中的任意元素

定义要执行的操作:

<animations:StoryBoard 
                x:Key="ProfileImageAnimation"    
                Target="{x:Reference ProfileImage}">
                <animations:FadeInAnimation 
                   Direction="Up"
                    Duration="500" />
</animations:StoryBoard>

要触发动画的事件有:

<ContentPage.Triggers>
        <EventTrigger Event="Appearing">
            <triggers:BeginAnimation   
                Animation="{StaticResource ProfileImageAnimation}" />
        </EventTrigger>
</ContentPage.Triggers>

您将要影响的元素:

<ctrl:UserProfileImageControl
                        WidthRequest="105"
                        HeightRequest="105"
                        BorderColor="{StaticResource ProfileGrayColorHexString}"
                        ProfileImage="{Binding Profile.PhotoUrl}"
                        UpdatePhotoCommand="{Binding UpdatePhotoCommand}"
                        HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand" />

所有的源代码都是可用的,开始使用并不难


祝你好运

这可以使用scrollview实现。这是一个简单的代码片段

<ContentPage.Content>
    <ScrollView x:Name="scr">

    Your Stack Layout having entry and click button
    Add TapGestureRecognizer to entry control in this case it is username or password whichever you want.
    How to add TapGestureRecognizer. You can look at here.

   </ScrollView>
</ContentPage.Content>

这通常不是在Xamarin.Forms中设置项目动画的方式。检查一下。西蒙,请对我在回答中写的内容稍加注意。我没有说这是一种制作动画的方法,我展示了一个如何解决一个特定问题的例子——事实上,这就是用户提出的问题。尽管标题说明了一件事,但正如他所描述的,他的问题是另一件事。用户的问题不在于如何制作动画(尽管标题如此),而在于当键盘打开时内容被隐藏。
field.GestureRecognizers.Add(new TapGestureRecognizer
{
    Command = new Command(async () => 
    { 
            await ScollTest();
    }),
    NumberOfTapsRequired = 1,
});

private async void ScollTest()
{
  // Then adjust your scroll this way.
  await scr.ScrollToAsync(100, 1000, true);
}