Xamarin 导航页面+;转盘页面:奇怪的滚动错误

Xamarin 导航页面+;转盘页面:奇怪的滚动错误,xamarin,xamarin.forms,carousel,Xamarin,Xamarin.forms,Carousel,我现在正在玩CarouselPage示例,因为我想转到其他页面,所以我以NavigationPage作为主页面启动应用程序: public App() { InitializeComponent(); // Need navigation to have modal/nonmodal pages //MainPage = new MainPage(); MainPage = new NavigationPage(n

我现在正在玩
CarouselPage
示例,因为我想转到其他页面,所以我以
NavigationPage
作为主页面启动应用程序:

    public App()
    {
        InitializeComponent();

        // Need navigation to have modal/nonmodal pages
        //MainPage = new MainPage();
        MainPage = new NavigationPage(new MainPage());
    }
XAML为iPhone X添加了安全区域,并删除了导航栏:

<?xml version="1.0" encoding="utf-8"?>
<CarouselPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Stoa" x:Class="Test.MainPage"
              xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" 
              ios:Page.UseSafeArea="true" 
              NavigationPage.HasNavigationBar="False">            
    <ContentPage>
        <ContentPage.Padding>
            <OnPlatform x:TypeArguments="Thickness">
                <On Platform="iOS, Android" Value="0,40,0,0" />
            </OnPlatform>
        </ContentPage.Padding>
        <StackLayout>
            <Label Text="Green" FontSize="Medium" HorizontalOptions="Center" />
            <Button BackgroundColor="Green" WidthRequest="200" HeightRequest="200" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
        </StackLayout>
    </ContentPage>
    <ContentPage>
        <ContentPage.Padding>
            <OnPlatform x:TypeArguments="Thickness">
                <On Platform="iOS, Android" Value="0,40,0,0" />
            </OnPlatform>
        </ContentPage.Padding>
        <StackLayout>
            <Label Text="Blue" FontSize="Medium" HorizontalOptions="Center" />
            <Button BackgroundColor="Blue" WidthRequest="200" HeightRequest="200" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
        </StackLayout>
    </ContentPage>
</CarouselPage>

问题是,现在用户可以垂直滚动,它会丢失边距,显然:

有办法解决这个问题吗

另一种选择是,如何导航远离旋转木马视图或“伪造”旋转木马

此“安全区域滚动偏移”可以通过设置UIScrollView的自定义iOS CarouseLPageRender修复 ContentInsetAdjustmentBehavior to从不

更新:上一个代码示例选中了UIView。子视图[0]是OneElementChanged中的UIScrollView,这可能引发System.IndexOutOfRangeException,导致SIGABRT崩溃。因此,我们在ViewDidLoad中检查它,如下所示:

[程序集:导出渲染器(typeof(CarouselPage)、typeof(customcarouselpagerender))]
命名空间MyApp.iOS.Renderers
{
公共类CustomRouseLPagender:CarouseLPagender
{
公共覆盖无效ViewDidLoad()
{
base.ViewDidLoad();
//在iOS 11上防止垂直旋转木马滚动,
//我们只需要旋转木马中的水平滚动
if(UIDevice.CurrentDevice.CheckSystemVersion(11,0))
{
View.Subviews.OfType().Single().ContentInsetAdjustmentBehavior=
UIScrollViewContentInsetAdjustmentBehavior.Never;
}
} 
}
}
[assembly: ExportRenderer(typeof(CarouselPage), typeof(CustomCarouselPageRenderer))]
namespace MyApp.iOS.Renderers
{
    public class CustomCarouselPageRenderer : CarouselPageRenderer
    {
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            //Prevent vertical carousel scroll on iOS 11, 
            //we only want horizontal scroll in the carousel
            if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
             View.Subviews.OfType<UIScrollView>().Single().ContentInsetAdjustmentBehavior =
             UIScrollViewContentInsetAdjustmentBehavior.Never;
            }
        } 
    }
}