如何判断当前运行的 Apple Watch 尺寸/尺寸是 38 毫米还是 42 毫米? [英] How to tell if current running Apple Watch size/dimension is 38mm or 42mm?

查看:145
本文介绍了如何判断当前运行的 Apple Watch 尺寸/尺寸是 38 毫米还是 42 毫米?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道 Apple Watch 有两种屏幕尺寸:38mm 和 42mm.WKInterfaceDevice 类提供了一个名为 screenBounds 的可读属性.我为 WKInterfaceDevice 写了一个扩展,试图添加一个方法来检测当前设备类型.

We know that there are two screen sizes for Apple Watch: 38mm and 42mm. The WKInterfaceDevice class provides a readable property named screenBounds. I wrote an extension for WKInterfaceDevice, trying to add a method to detect current device type.

import WatchKit

enum WatchResolution {

    case Watch38mm, Watch42mm
}

extension WKInterfaceDevice {

    class func currentResolution() -> WatchResolution {

        let watch38mmRect = CGRectMake(0.0, 0.0, 136.0, 170.0)
        let watch42mmRect = CGRectMake(0.0, 0.0, 156.0, 195.0)

        let currentBounds = WKInterfaceDevice.currentDevice().screenBounds

        if CGRectEqualToRect(currentBounds, watch38mmRect) {

            return WatchResolution.Watch38mm
        } else {

            return WatchResolution.Watch42mm
        }
    }
}

这是检测 Apple Watch 尺寸的正确方法吗?我在 Apple 文档中缺少另一种方法吗?

Is that the correct method to detect Apple Watch size? Is there another method I am missing in the Apple docs?

推荐答案

这就是我正在做的:

enum WatchModel {
    case w38, w40, w42, w44, unknown
}

extension WKInterfaceDevice {

    static var currentWatchModel: WatchModel {
        switch WKInterfaceDevice.current().screenBounds.size {
        case CGSize(width: 136, height: 170):
            return .w38
        case CGSize(width: 162, height: 197):
            return .w40
        case CGSize(width: 156, height: 195):
            return .w42
        case CGSize(width: 184, height: 224):
            return .w44
        default:
            return .unknown
    }
  }
}

这篇关于如何判断当前运行的 Apple Watch 尺寸/尺寸是 38 毫米还是 42 毫米?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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