滚动时,标签在Xamarion Forms IOS中稍微向上移动

时间:2020-09-12 11:54:28

标签: xamarin xamarin.forms xamarin.android xamarin.ios

在向下滚动选项卡内的内容页面时,选项卡有问题。我有三个内容页的TabbedPage。在ContentPages中滚动时,选项卡在IOS平台中向上移动一点,而在Android中则显示为正常。所有ContentPages的反应都相同。这是我的第一个ContentPage,但是其余的则具有正常的Grid / TableView而没有滚动。

<FlexLayout Direction="Column">
            <FlexLayout FlexLayout.Grow="1">
                <ScrollView>
                <Grid Padding="5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                        <StackLayout Orientation="Vertical" Grid.Row="0">
                            <StackLayout x:Name="listView" Padding="0,10,0,10"
                             BindableLayout.ItemsSource="{Binding TopPages}"
                             BindableLayout.ItemTemplate="{StaticResource PageListItemTemplate}">
                        </StackLayout>
                    </StackLayout>
                    <StackLayout Orientation="Vertical" Grid.Row="1" HeightRequest="350">
                        <StackLayout HorizontalOptions="FillAndExpand" Orientation="Horizontal">
                            <Label Text="Reciters" HorizontalOptions="StartAndExpand" Style="{StaticResource DesLabel}"/>
                            <Label Text="Show All" FontSize="Medium" 
                                    TextColor="{DynamicResource PrimaryTextColor}" HorizontalOptions="End">
                                <Label.GestureRecognizers>
                                    <TapGestureRecognizer Command="{Binding RecitersListCommand}" CommandParameter="{StaticResource TypeOne}"/>
                                </Label.GestureRecognizers>
                            </Label>
                        </StackLayout>
                        <Frame Style="{StaticResource DefaultFrame}" Padding="5">
                            <CollectionView x:Name="reciterItemView" ItemsSource="{Binding Reciters}"
                                SelectionMode="Single" ItemTemplate="{StaticResource ItemTemplate}">
                                    <CollectionView.ItemsLayout>
                                        <GridItemsLayout Orientation="Horizontal" VerticalItemSpacing="5" 
                                                 HorizontalItemSpacing="5" Span="2" />
                                    </CollectionView.ItemsLayout>
                                </CollectionView>
                        </Frame>
                    </StackLayout>
                    <StackLayout Orientation="Vertical" Grid.Row="2" HeightRequest="350">
                        <StackLayout HorizontalOptions="FillAndExpand" Orientation="Horizontal">
                            <Label Text="Translations" HorizontalOptions="StartAndExpand" Style="{StaticResource DesLabel}"/>
                            <Label Text="Show All" FontSize="Medium" TextColor="{DynamicResource PrimaryTextColor}" HorizontalOptions="End">
                                    <Label.GestureRecognizers>
                                        <TapGestureRecognizer Command="{Binding RecitersListCommand}" CommandParameter="{StaticResource TypeTwo}"/>
                                </Label.GestureRecognizers>
                            </Label>
                        </StackLayout>
                        <Frame Style="{StaticResource DefaultFrame}">
                            <CollectionView x:Name="translationItemView" ItemsSource="{Binding RecitersWithTranslation}"
                                SelectionMode="Single" ItemTemplate="{StaticResource ItemTemplate}" >
                                    <CollectionView.ItemsLayout>
                                        <GridItemsLayout Orientation="Horizontal"  Span="2" />
                                    </CollectionView.ItemsLayout>
                                </CollectionView>
                        </Frame>
                    </StackLayout>
                </Grid>
                </ScrollView>
            </FlexLayout>
            <StackLayout VerticalOptions="Center" HorizontalOptions="FillAndExpand" 
                             BackgroundColor ="{AppThemeBinding Light={StaticResource LightPageBackgroundSecondaryColor},
                                    Dark={StaticResource DarkPageBackgroundSecondaryColor}}">
                <StackLayout.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding NavigateToPlayerPageCommand}"/>
                </StackLayout.GestureRecognizers>
            </StackLayout>
        </FlexLayout>

Dark Space in the tabbed area appears while scrolling down

页面中的资源

<DataTemplate x:Key="PageListItemTemplate">
            <StackLayout Orientation="Vertical">
                <StackLayout Orientation="Horizontal" HorizontalOptions="StartAndExpand">
                    <Label Style="{StaticResource DesLabel}" HorizontalOptions="Start" VerticalOptions="Center" Text="{Binding Title}"/>
                </StackLayout>
                <BoxView Style="{StaticResource HorizentalLine}"></BoxView>
                <StackLayout.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding BindingContext.TopPageCommand, Source={x:Reference listView}}" CommandParameter="{Binding .}"/>
                </StackLayout.GestureRecognizers>
            </StackLayout>
        </DataTemplate>
        <DataTemplate x:Key="ItemTemplate">
            <StackLayout Orientation="Vertical" HorizontalOptions="Center" Padding="0,5,0,0">
                <FFImage:CachedImage HeightRequest="100" WidthRequest="100" Source="{Binding ImagePath}" Style="{StaticResource FFImageDefaultStyleWithoutBinding}">
                    <FFImage:CachedImage.Transformations>
                        <FFimageTransformation:CircleTransformation></FFimageTransformation:CircleTransformation>
                    </FFImage:CachedImage.Transformations>
                </FFImage:CachedImage>
                <Label Text="{Binding Name}" FontSize="Small" WidthRequest="150" HorizontalTextAlignment="Center" LineBreakMode="WordWrap" />
                <StackLayout.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding BindingContext.OpenReciterChapterCommand, 
                                                    Source={x:Reference reciterItemView}}" CommandParameter="{Binding .}">
                    </TapGestureRecognizer>
                </StackLayout.GestureRecognizers>
            </StackLayout>
        </DataTemplate>

1 个答案:

答案 0 :(得分:0)

查看完我的每段代码后,终于找到了问题所在。实际上,问题不在于设计或XAML。这是我在App.cs中使用的以下语句。

public App()
{
     InitializeComponent();

     var navigationPage = new Xamarin.Forms.NavigationPage(new MainPage());
     navigationPage.On<iOS>().SetPrefersLargeTitles(true); // This line caused the problem.
     MainPage = navigationPage;
}

删除该行即可解决问题。