MvvmCross MvxFormFactor特定的iPad/iPhone属性 [英] MvvmCross MvxFormFactorSpecific iPad/iPhone Attributes

查看:83
本文介绍了MvvmCross MvxFormFactor特定的iPad/iPhone属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我同时拥有iPhone和iPad专用的视图控制器,它们分别具有MvxFormFactorSpecific(MvxTouchFormFactor.Phone)和MvxFormFactorSpecific(MvxTouchFormFactor.Pad)属性.在iPad上运行该应用程序时,将找到并实例化正确的视图.但是,当该应用在4英寸的iPhone上运行时,它抛出一个异常,提示找不到...的视图."这是一个错误还是我做错了什么?

I have both iPhone and iPad specific view controllers which have MvxFormFactorSpecific(MvxTouchFormFactor.Phone) and MvxFormFactorSpecific(MvxTouchFormFactor.Pad) attributes, respectively. When the app is run on an iPad, the correct view is found and instantiated. However, when the app is run on a 4" iPhone, it throws an exception saying the "Could not find view for...". So is this a bug or am I doing something wrong?

此外,MvxTouchFormFactor.Phone是否默认针对4英寸iPhone,还是需要使用MvxTouchFormFactor.TallPhone明确针对它们?

Also, does MvxTouchFormFactor.Phone defaultly target 4" iPhones or do they need to be explicitly targeted with MvxTouchFormFactor.TallPhone?

推荐答案

此功能的实现位于:

  • https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Touch/Platform/MvxTouchPlatformProperties.cs
  • https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Touch/Views/MvxFormFactorSpecificAttribute.cs

形状因子本身定义为:

    public MvxTouchFormFactor FormFactor
    {
        get
        {
            switch (UIDevice.CurrentDevice.UserInterfaceIdiom)
            {
                case UIUserInterfaceIdiom.Phone:
                    if (UIScreen.MainScreen.Bounds.Height*UIScreen.MainScreen.Scale >= 1136)
                        return MvxTouchFormFactor.TallPhone;

                    return MvxTouchFormFactor.Phone;

                case UIUserInterfaceIdiom.Pad:
                    return MvxTouchFormFactor.Pad;

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
    }

所以-您可以看到Phone当前与TallPhone

So - you can see that Phone is not currently the same as TallPhone

我怀疑您最简单的方法可能是编写您自己的条件属性-这非常容易-仅查看MvxFormFactorSpecificAttribute的定义并将其用作您自己的属性的基础:

I suspect that your easiest way forwards here is probably to write your own conditional attribute - this is pretty easy to do - just look at how MvxFormFactorSpecificAttribute is defined and use it as the basis for your own attribute:

[AttributeUsage(AttributeTargets.Class)]
public class MyFormFactorSpecificAttribute
    : MvxConditionalConventionalAttribute
{
    public override bool IsConditionSatisfied
    {
        get
        {
            // put your logic here - could use Mvx.Resolve<IMvxTouchPlatformProperties>()
            return TODO;
        }
    }
}

如果您认为您的属性对其他用户有用,那么我肯定会接受向MvvmCross提出的潜在拉取请求以进行改进.

If you think your attribute would be good for other users, I'd definitely be open to potential pull requests back to MvvmCross here for improvements.

或者,您可以简单地将冲突的视图标记为Unconventional,并可以在Setup

Alternatively, you could simply mark your conflicting views as Unconventional and could manually add them to the View-ViewModel lookup during Setup

抱歉,这方面有些混乱.例如我们已经将MvxTouchPlatformProperties标记为过时,因为我们确实希望/希望这种功能将来会在某些时候被CrossCore功能取代.

Sorry there is some confusion in this area. e.g. we've already marked MvxTouchPlatformProperties as obsolete as we do anticipate/hope that this sort of functionality will be replaced by CrossCore functionality at some point in the future.

这篇关于MvvmCross MvxFormFactor特定的iPad/iPhone属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆