【问题标题】:Detecting orientation of iPhone using C++使用 C++ 检测 iPhone 的方向
【发布时间】:2019-10-28 23:32:54
【问题描述】:

Embarcadero C++Builder 10.3.2 企业版

搜索互联网,我找不到任何 FMX 代码。基于 Delphi 代码,这应该可以工作,但编译器不喜欢它

if (Application->FormFactor->Orientations == Fmx::Types::TScreenOrientations::Landscape) {
    //Landscape
}

此外,Application->FormFactor->Orientations 的值是相同的,无论 iphone 的方向如何。 {系统::SetBase = {数据 = {[0] = 11 '\v'}}} 如何确定方向?

【问题讨论】:

    标签: c++ firemonkey c++builder-10.3-rio


    【解决方案1】:

    Orientations 属性是 TFormOrientations,它是 System::SetTFormOrientation 值。您不能使用 Set::operator== 将其与单个值进行比较,这就是您收到编译器错误的原因。但是,您可以使用Set::Contains() 方法来检查它是否具有给定值,例如:

    if (Application->FormFactor->Orientations.Contains(Fmx::Forms::TFormOrientation::Landscape)) {
        //...
    }
    

    在任何情况下,Orientations 属性指定应用程序的表单允许采用的方向(值 11 将其第 1、第 2 和第 4 位设置为 1,对应于启用的PortraitLandscapeInvertedLandscape 方向)。它不报告设备的 当前 方向是什么。为此,请改用IFMXScreenService::GetScreenOrientation() 方法,例如:

    _di_IFMXScreenService ScreenService;
    if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), &ScreenService)) {
        if (ScreenService->GetScreenOrientation() == Fmx::Types::TScreenOrientation::Landscape) {
            //...
        }
    }
    
    

    【讨论】:

    • 雷米,我知道你是对的。但我很好奇您是否发现我使用屏幕尺寸检查的方法存在任何实际问题。谢谢
    • @relayman357 检查屏幕尺寸只会告诉您设备是向上/向下还是向左/向右很远,但它不区分正常横向(屏幕顶部在左侧)和反向横向(屏幕顶部向右),或正常纵向(屏幕顶部向上)和反向纵向(屏幕顶部向下)。方向是相对于设备上的固定点(例如供应商徽标、特定角等),并反映该点相对于物理空间中设备其余部分的位置
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-16
    • 1970-01-01
    • 2011-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多