iOS 上的 SwipeView 滑动转换模式

此 iOS 平台特定功能控制打开 SwipeView 时使用的转换。 其使用方式是在 XAML 中将 SwipeView.SwipeTransitionMode 可绑定属性设置为 SwipeTransitionMode 枚举的值:

<ContentPage ...
             xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core">
    <StackLayout>
        <SwipeView ios:SwipeView.SwipeTransitionMode="Drag">
            <SwipeView.LeftItems>
                <SwipeItems>
                    <SwipeItem Text="Delete"
                               IconImageSource="delete.png"
                               BackgroundColor="LightPink"
                               Invoked="OnDeleteSwipeItemInvoked" />
                </SwipeItems>
            </SwipeView.LeftItems>
            <!-- Content -->
        </SwipeView>
    </StackLayout>
</ContentPage>

或者,可以使用 Fluent API 从 C# 使用它:

using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
...

SwipeView swipeView = new Xamarin.Forms.SwipeView();
swipeView.On<iOS>().SetSwipeTransitionMode(SwipeTransitionMode.Drag);
// ...

SwipeView.On<iOS> 方法指定此平台特定仅在 iOS 上运行。 Xamarin.Forms.PlatformConfiguration.iOSSpecific 命名空间中的 SwipeView.SetSwipeTransitionMode 方法用于控制打开 SwipeView 时使用的转换。 SwipeTransitionMode 枚举提供了两种可能的值:

  • Reveal 表示轻扫项目将在轻扫 SwipeView 内容时显示,并且是 SwipeView.SwipeTransitionMode 属性的默认值。
  • Drag 表示在轻扫 SwipeView 内容时,轻扫项目将被拖入视图。

此外,SwipeView.GetSwipeTransitionMode 方法还可用于返回应用于 SwipeTransitionModeSwipeView

结果是指定的 SwipeTransitionMode 值被应用到 SwipeView 中,从而控制打开 SwipeView 时使用的转换:

iOS 上的 SwipeView SwipeTransitionModes 的屏幕截图