【问题标题】:ExtendedSplashScreen with custom size and Animation C# UWP具有自定义大小和动画 C# UWP 的 ExtendedSplashScreen
【发布时间】:2016-06-01 21:02:29
【问题描述】:

我正在尝试通过添加 ExtendedSplashScreen 来完成我的 UWP 应用程序。在 UWP 中,SplashScreen 应具有特定尺寸,并应添加到页面中心的 SplashRect 中。 我要:

  1. Splash 占据所有屏幕尺寸(适用于不同的屏幕尺寸)
  2. 制作一个不同图片依次显示的动画。

这可以实现吗? UWP 设计指南中是否允许这样做?有什么帮助吗?

【问题讨论】:

  • 给它a shot 并在您第一次尝试后遇到特定问题时回来。
  • “使用扩展的初始屏幕来显示多个不同的初始屏幕图像会分散您的注意力,并且可能会让您的用户感到不安或困惑。” - Guidelines for splash screens

标签: c# xaml animation uwp splash-screen


【解决方案1】:

这可以实现吗?

是的,我已经上传了一个完整的演示以满足您的要求。您可以下载CSplashScreen 解决方案进行测试。 为了满足您的要求,

制作一个显示不同图片的动画。

我用一个 FlipView 控件和一个DispatcherTimer 来实现它。所以闪屏可以自动一张一张的显示图片。

Splash 占据所有屏幕尺寸(适用于不同的屏幕尺寸)

FlipView 始终适合窗口的大小,并且图像在不同设备中显示为全窗口。

Xaml 代码:

<FlipView x:Name="ImageFlipView">
   <Image Source="ms-appx:///Assets/caffe600320.jpg" Stretch="Fill" />
   <Image Source="ms-appx:///Assets/cafee2.jpg" Stretch="Fill" />
   <Image Source="ms-appx:///Assets/caffe3.jpg" Stretch="Fill" />
</FlipView>

后面的代码:

private SplashScreen splash; // Variable to hold the splash screen object
internal bool dismissed = false; // Variable to track splash screen dismi
internal Frame rootFrame;
private readonly DispatcherTimer _timer;

public ExtendedSplash(SplashScreen splashscreen, bool loadState)
{
    this.InitializeComponent();
    StatusBar statusbar = StatusBar.GetForCurrentView();
    statusbar.HideAsync();
    if (splash != null)
    {
        splash.Dismissed += new TypedEventHandler<SplashScreen, Object>(D
    }
    rootFrame = new Frame();
    _timer = new DispatcherTimer
    {
        Interval = TimeSpan.FromSeconds(2)
    };
    _timer.Tick += ChangeImage;
    _timer.Start();
}

private void ChangeImage(object sender, object e)
{
    var totalItems = ImageFlipView.Items.Count;
    var newItemIndex = (ImageFlipView.SelectedIndex + 1) % totalItems;
    ImageFlipView.SelectedIndex = newItemIndex;
}   
void DismissedEventHandler(SplashScreen sender, object e)
{
    dismissed = true;            
}

UWP 设计指南中是否允许这样做?

来自官方文档Display a splash screen for more time,

遵循以下建议,确保您的扩展启动画面准确地模仿默认启动画面:

该文档提供了有关创建您自己的扩展初始屏幕的建议。最佳做法是遵循建议。启动画面的指南也建议我们:

  • 不要使用初始屏幕或扩展的初始屏幕来显示广告。
  • 不要将扩展的初始屏幕用作显示多个不同初始屏幕图像的机制。启动画面和扩展启动画面的目的是为您的用户提供流畅、优美的加载体验。
  • 不要使用初始屏幕或扩展的初始屏幕来显示“关于”页面。

【讨论】:

  • 小心这段代码。它有内存泄漏,因为 tick 事件永远不会被取消订阅。 JetBrains 有一个 explanation here
猜你喜欢
  • 1970-01-01
  • 2013-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-14
  • 2014-02-20
相关资源
最近更新 更多