ios - MvvmCross 6 中的子类 UIWindow

标签 ios xamarin mvvmcross

在更新到 MvvmCross 6 之前,我们曾经在 iOS 上对 UIWindow 进行子类化,并将其设置为 AppDelagate 中的 keywindow 来检测应用程序中的所有事件,我们过去使用设置的方式现在在 MvvmCross 6.0 中已更改。

https://www.mvvmcross.com/mvvmcross-6.0.0-release/

应用程序启动

“应用程序使用 MvvmCross 启动的方式现在变得更加清晰。MvxAppStart 现在由框架统一自动调用。这意味着您可以在 iOS 等平台上安全地删除初始化代码(框架现在还将创建为您提供的关键窗口)。”

现在看不到设置自己的 keywindow 并将其传递给 MvvmCross 的方法,有什么建议吗?

谢谢

尼尔

最佳答案

正如您所说,MvvmCross 6 现在负责为您分配 KeyWindow。 事实上,当阅读source code时MvvmCross 6+ 的,您可以在 FinishedLanchingWithOptions 中看到这一点:

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        //window is being assigned here by MvvmCross
        if (Window == null)
            Window = new UIWindow(UIScreen.MainScreen.Bounds);

        MvxIosSetupSingleton.EnsureSingletonAvailable(this, Window).EnsureInitialized();

        RunAppStart(launchOptions);

        FireLifetimeChanged(MvxLifetimeEvent.Launching);
        return true;
    }

但是,他们没有为您提供这样做的钩子(Hook)。为了解决这个问题,我建议重写并执行如下操作:

[Register(nameof(AppDelegate))]
public class AppDelegate : MvxApplicationDelegate<Setup, Core.App>
{
    public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        if (Window == null)
            Window = new CustomWindow(UIScreen.MainScreen.Bounds);

        base.FinishedLaunching(application, launchOptions);
    }

}

希望这有帮助

关于ios - MvvmCross 6 中的子类 UIWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54146822/

相关文章:

ios - UITableViewCell 中的 UIImage 正在调整行选择和从推送 View 返回时的大小

c# - 使用 mvvmcross 显示 View 模型时无法解析当前的顶级 Activity

mvvm - MVVMCross 中 View 模型的 UI 线程问题

android - Xamarin/Visual Studio 2017 应用程序部署成功,但在 android 模拟器中没有显示应用程序?

ios - Rx swift : using rx_refreshing for uirefreshcontrol

ios - AVComposition 在 Airplay 上中断

iOS - 无法在按钮上设置文本

ios - 在IOS上测试:System.ArgumentException

android - Xamarin Android 发布构建错误

ios - 如何在 ReactiveCocoa 4 中创建自定义信号?