gpt4 book ai didi

xamarin - 导航页面 + 轮播页面 : weird scroll error

转载 作者:行者123 更新时间:2023-12-02 03:24:22 24 4
gpt4 key购买 nike

我现在正在使用 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>

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

weirdscroll

有办法解决这个问题吗?

或者,如何离开轮播 View 或“伪造”轮播?

最佳答案

This "Safe Area scroll offset" can be fixed with a custom iOS CarouselPageRenderer that sets the UIScrollView ContentInsetAdjustmentBehavior to Never

Updated: previous code example checked UIView.Subviews[0] is UIScrollView in OnElementChanged, this could throw a System.IndexOutOfRangeException causing a SIGABRT crash. So instead we check it in ViewDidLoad as suggested here: https://forums.xamarin.com/discussion/104385/ios-11-carousel-page-issues

[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;
}
}
}
}

关于xamarin - 导航页面 + 轮播页面 : weird scroll error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53834759/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com