【问题标题】:How can I add transitions between views/pages when I use SwipeGestureRecognizer in iOS在 iOS 中使用 SwipeGestureRecognizer 时如何在视图/页面之间添加转换
【发布时间】:2020-10-29 17:29:42
【问题描述】:

我在这样的 ContentPage 中使用 ContentView

<ContentView x:Name="MyContent"
                         VerticalOptions="FillAndExpand"
                         HorizontalOptions="FillAndExpand">
                <ContentView.GestureRecognizers>
                    <SwipeGestureRecognizer Swiped="SwipLeft" Direction="Left"/>
                    <SwipeGestureRecognizer Swiped="SwipRight" Direction="Right"/>
                </ContentView.GestureRecognizers>
 </ContentView>

在后面的代码中,我根据 SwipeDirection 将相关内容设置为 ContentView,如下所示。和 SwipRight 一样。

private void SwipLeft(object sender, SwipedEventArgs e)
        {
            
                if (e.Direction == SwipeDirection.Left)
                {
                   //set the relavent page content here               
                }                                      
        }

我需要设置在页面之间滑动时出现的动画或过渡。我只在 iOS 上需要这个。任何人都可以帮助我,或者任何方法都知道任何人可以实现这一目标?

你可以从这张快照中得到灵感 click here for image 所有内容和一切都已完成,我只需要在页面之间添加过渡即可。

【问题讨论】:

  • 您是否尝试过使用 CarouselView? docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/…。您无法自定义动画,但它确实有效。
  • 您的屏幕截图看起来像标签控件。这是你想要的吗?
  • @xerx 是的。我和那个绑在一起。但这并没有满足我的所有要求。所以我只是摆脱它
  • @Anand 是的。我需要带有顶部选项卡的 iOS 选项卡式页面,这是主页面的子页面。我已经完成了带有自定义功能的标签页。现在我只需要添加一些过渡。

标签: ios xamarin xamarin.forms xamarin.ios swipe-gesture


【解决方案1】:

您可以使用 TabbedPage 。似乎您想让选项卡显示在屏幕顶部。在您的情况下,您可以从 nuget 安装插件 TopTabbedPage

用法

<forms:TopTabbedPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="Naxam.Demo.TestPage"
    xmlns:views="clr-namespace:Naxam.Demo"
    xmlns:forms="clr-namespace:Naxam.Controls.Forms;assembly=Naxam.TopTabbedPage.Forms"
    BarTextColor="#00b9e1"
    BarIndicatorColor="#00b9e1"
    BarBackgroundColor="#ffffff"
    Title="MyRide">
    <views:Page1 />  // here is the content page , you need to put each contentview in independent ContenPage
    <views:Page2 />
</forms:TopTabbedPage>

在 iOS 项目中 -> AppDelegate.cs

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        // Override point for customization after application launch.
        // If not required for your application you can safely delete this method
        TopTabbedRenderer.Init();
       
        Xamarin.Forms.Forms.Init();

        LoadApplication(new App());

  
        return base.FinishedLaunching(app, options);
    }

有关插件的更多详细信息,您可以参考github project site

【讨论】:

  • 我试过这个 TopTabbedPage。不幸的是,它仅适用于主页。但我需要在子页面中使用此选项卡式页面。我已经完成了一些定制。一切正常。我只需要在你从让向右和从右向左滑动时添加一些过渡。
  • MyContent.Opacity = 0; MyContent.FadeTo (1, 000); 我试过这样的东西,它工作正常。但我需要一个过渡,比如从左到右/从右到左移动页面
  • 你可以使用 ScrollView 或 CarouselView 。
猜你喜欢
  • 1970-01-01
  • 2020-05-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多