ios - 从 PHAsset 获取视频时如何检测视频是否为横向/纵向?

标签 ios swift avasset phasset

我正在从 PHAsset 获取视频,以便用户可以选择视频并导入以执行编辑。但用户应该只能选择横向视频,如果用户选择纵向视频,她/他会收到警告消息,指出其为纵向视频,因此无法导入进行编辑。

一种方法是从 PHFetchResults 的 URL 创建 AVAsset,然后检查 PreferredTransform,但这会是非常昂贵的操作,对吧?

有没有办法在不创建AVasset的情况下做到这一点?

最佳答案

https://developer.apple.com/library/ios/documentation/Photos/Reference/PHAsset_Class/

var pixelWidth: Int { get }

var pixelHeight: Int { get }

The width and height, in pixels, of the asset’s image or video data. (read-only)

If the asset’s content has been edited, this property describes the size of the current version of the asset. Availability iOS (8.0 and later)

if asset!.pixelHeight > asset!.pixelWidth {
 // will be portrait video or Image
}

适用于 iOS 8.0 及更高版本。

关于ios - 从 PHAsset 获取视频时如何检测视频是否为横向/纵向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37596555/

相关文章:

ios - 当使用大量输入调用时,Swift 中的递归函数会崩溃

xcode - 代码从 2.0 到 1.0 的转换

iphone - NSString 变量不是 NSstring

ios - 使方法在对象上工作

ios - 实现可滚动的水平菜单

ios - 在 Swift 2 的 viewDidLoad 中选择了两个 TabBar 图标?

ios - AVAssetResourceLoaderDelegate 和 HLS 不起作用?

swift - 以自定义大小阅读图库视频

ios - CGAffineTransform 应用附加旋转

iphone - 具有编辑和删除功能的UIView叫什么?