2016-03-15 73 views
3

非常好的早晨,我试图实现单击UserName StackPanel时的功能,以便键盘不会隐藏信息。但是,这不是最好的选择,我在iOS和Android上工作。你可以帮帮我吗。Xamarin - 动画StackLayout

<?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 UserName normal - Chase in mode up stacklayout

回答

-1

对于我已经从你的问题的理解,你想办法确保,当键盘弹出的,它不包括在该条目和/或其他相关信息屏幕,对吧?

这样做的方法是让您的内容在ScrollView之内,这样用户就可以根据需要进行滚动。此外,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> 
+0

你的代码如何在动画项目Xamarin.Forms这是不正常。查看[Github上的BikeShare360应用程序](https://github.com/Microsoft/BikeSharing360_MobileApps)。 – adamhill

+0

C'omon,请对我在答复中写下的内容稍加注意。我没有说这是一种动画制作的方式,我展示了一个如何解决特定问题的例子 - 事实上,这是用户问的问题。虽然标题说了一件事,但他的问题是另一个问题,正如他所描述的那样。 –

-1

这不是正常情况下你是如何动画在Xamarin.Forms项目。检查出BikeShare360 app on Github

这是一个漂亮的应用程序,并使用第三方动画库和自定义Storyboard 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" /> 

所有的资源都可用,并且开始并不难。

祝你好运!

+0

用户的问题不在于如何设置动画(尽管是标题),而是关于键盘打开时隐藏的内容。 –

0

这可以使用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> 

然后在后面

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); 
} 
相关问题