phaseset 子类型 rawValue 意味着 swift

问题描述 投票:0回答:2

我正在尝试检测 PHAsset 的子类型。

asset.subtypes.rawvalue -> UInt

我找到了子类型 .video (rawValue: 0) 和 photoLive (rawValue: 8) 的含义,但我有带有 HDR 选项的 livePhoto,子类型 rawavlue 是 10,我没有找到该值的含义。 有人知道 PHAsset 子类型的所有 rawValue 含义吗? 谢谢

swift phasset
2个回答
3
投票

根据PHAssetMediaSubtype

文档:

媒体子类型是位掩码值,因此您可以使用组合它们 按位运算符来测试多个子类型。

该定义有助于:

typedef enum PHAssetMediaSubtype : NSUInteger {
    PHAssetMediaSubtypeNone = 0,
    PHAssetMediaSubtypePhotoPanorama = (1UL << 0),
    PHAssetMediaSubtypePhotoHDR = (1UL << 1),
    PHAssetMediaSubtypePhotoScreenshot = (1UL << 2),
    PHAssetMediaSubtypePhotoLive = (1UL << 3),
    PHAssetMediaSubtypePhotoDepthEffect = (1UL << 4),
    PHAssetMediaSubtypeVideoStreamed = (1UL << 16),
    PHAssetMediaSubtypeVideoHighFrameRate = (1UL << 17),
    PHAssetMediaSubtypeVideoTimelapse = (1UL << 18)
} PHAssetMediaSubtype;

因此,如果子类型是 10,那么 10 就是 8+2(唯一可能的“子值”),它就是值 8 (

.photoLive
) 和值 2 (.HDR)。


0
投票

在 Swift 中 PHAssetMediaSubtype 是一个 OptionSet,您可以使其符合

CustomStringConvertible
并生成人类可读的值 :

extension PHAssetMediaSubtype: @retroactive CustomStringConvertible {
    public var description: String {

        var debugDescriptions: [(Self, String)] = [
            // Photo subtypes
            (.photoPanorama, ".photoPanorama"),
            (.photoHDR, ".photoHDR"),
            (.photoScreenshot, ".photoScreenshot"),
            (.photoLive, ".photoLive"),
            (.photoDepthEffect, ".photoDepthEffect"),
            // Video subtypes
            (.videoStreamed, ".videoStreamed"),
            (.videoHighFrameRate, ".videoHighFrameRate"),
            (.videoTimelapse, ".videoTimelapse")
        ]

        if #available(iOS 15, *) {
            debugDescriptions.append((.videoCinematic, ".videoCinematic"))
        }

        if #available(iOS 16, *) {
            debugDescriptions.append((.spatialMedia, ".spatialMedia"))
        }

        let options = debugDescriptions.filter { contains($0.0) }.map { $0.1 }
        let result = options.joined(separator: ", ")
        return "PHAssetMediaSubtype([\(result)])"
    }
}

可以像这样使用:

let foo = PHAssetMediaSubtype([.photoDepthEffect, .photoLive]))
print(foo)
© www.soinside.com 2019 - 2024. All rights reserved.