代码之家  ›  专栏  ›  技术社区  ›  senseiwa

NavigationPage+CarouselPage:奇怪的滚动错误

  •  0
  • senseiwa  · 技术社区  · 7 年前

    我在玩 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

    有办法解决这个问题吗?

    另一种方法是,如何从旋转木马视图中导航或“伪造”旋转木马?

    1 回复  |  直到 7 年前
        1
  •  2
  •   TouchBoarder    6 年前

    这个“安全区域滚动偏移”可以通过设置UIScrollView的自定义iOS carouselpagerender来修复 ContentInstadJustmentBehavior到 从未

    更新时间: 上一个代码示例checked UIView.Subviews[0]是OnElementChanged中的UIScrollView,这可能引发System.IndexAutoFrangeException,导致SIGABRT崩溃。因此,我们在ViewDidLoad中检查它,如下所示: 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;
                }
            } 
        }
    }
    
        2
  •  0
  •   pjrki    7 年前

    有一篇关于 https://github.com/alexrainman/CarouselView 当回购的所有者创建了自己的carousel并使用BindableProperties扩展它时,您只需设置方向即可。