我正在将我的 Xamarin 应用程序转换为 .NET MAUI,看起来像<ScrollView>
解决方案在 iOS 上的 .NET MAUI 应用程序上不起作用,或者我做错了什么。不过它在 Android 上运行得很好。有什么建议么?此外,同样的布局在 Xamarin 中运行良好。
我的表格如下所示:
<ScrollView
Orientation="Neither"
Padding="0"
HorizontalOptions="CenterAndExpand">
<Grid
RowDefinitions="500,Auto"
ColumnDefinitions="*">
<!-- Background Image -->
<Image
Grid.RowSpan="2"
Source="my_background_image.jpg"
Aspect="AspectFill"/>
<!-- Logo -->
<Image
Grid.Row="0"
Source="my_logo.png"
HeightRequest="130"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand"/>
<!-- Login Form -->
<VerticalStackLayout
Grid.Row="1"
HorizontalOptions="CenterAndExpand">
<Border
BackgroundColor="{StaticResource Gray100}"
Padding="3">
<Border.StrokeShape>
<RoundRectangle CornerRadius="5,5,5,5" />
</Border.StrokeShape>
<Entry
Text="{Binding UserName}"
BackgroundColor="White"
Placeholder="Email Address"
WidthRequest="350"/>
</Border>
<Border
BackgroundColor="{StaticResource Gray100}"
Padding="3"
Margin="0,10,0,0">
<Border.StrokeShape>
<RoundRectangle CornerRadius="5,5,5,5" />
</Border.StrokeShape>
<Entry
Text="{Binding Password}"
BackgroundColor="White"
Placeholder="Password"
WidthRequest="350"/>
</Border>
<Button
Text="SIGN IN"
TextColor="White"
BackgroundColor="{StaticResource Primary}"
FontAttributes="Bold"
CharacterSpacing="2"
Command="{Binding SubmitCommand}"
WidthRequest="350"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"
Margin="0,20,0,0"/>
<HorizontalStackLayout
HorizontalOptions="CenterAndExpand"
Margin="0,30,0,0">
<Border
BackgroundColor="Transparent"
Padding="5">
<Label
Text="New User Sign Up"
TextColor="White"
FontSize="12"/>
</Border>
<Border
BackgroundColor="Transparent"
Padding="5">
<Label
Text="|"
TextColor="White"
FontSize="12"
Margin="5,0,5,0"/>
</Border>
<Border
BackgroundColor="Transparent"
Padding="5">
<Label
Text="Forgot Password"
TextColor="White"
FontSize="12" />
</Border>
</HorizontalStackLayout>
</VerticalStackLayout>
</Grid>
</ScrollView>
要解决该问题,您可以move up
键盘显示时的登录表单和move down
隐藏键盘时它。
要检测键盘显示/隐藏事件,您可以将其挂钩Focused/Unfocused
进入事件。
最后一点是我们只需要它就可以做到这一点iOS平台。
示例代码
给个名字VerticalStackLayout
并在 Entry 上添加事件。
<VerticalStackLayout Grid.Row="1" HorizontalOptions="CenterAndExpand" x:Name="layout">
<Entry Text="{Binding UserName}" BackgroundColor="White" Placeholder="Email Address" WidthRequest="350" Focused="Entry_Focused" Unfocused="Entry_Unfocused"/>
处理后面代码中的逻辑
private void Entry_Focused(object sender, FocusEventArgs e)
{
if (DeviceInfo.Current.Platform == DevicePlatform.iOS)
{
layout.TranslateTo(0, -200, 50);
}
}
private void Entry_Unfocused(object sender, FocusEventArgs e)
{
if (DeviceInfo.Current.Platform == DevicePlatform.iOS)
{
layout.TranslateTo(0, 0, 50);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)