问题
I am fetching videos from PHAsset so user can choose the video and import to perform edit. But user should be only able to select video with Landscape orientation, if user select portrait video, she/he would get alert message saying that its portrait video and hence can not import to edit.
One way to do this is creating AVAsset from URL of PHFetchResults, and then checking a preferedTransform, but that would be very costly operation to do right?
Is there a way to do this without creating AVasset?
回答1:
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
}
Available in iOS 8.0 and later.
来源:https://stackoverflow.com/questions/37596555/how-to-detect-if-video-is-landscape-portrait-when-fetched-from-phasset