【发布时间】:2015-06-22 22:16:19
【问题描述】:
我正在构建 iOS 应用程序以从用户的照片库中选择屏幕截图。该应用程序有效,除了我可以显示所有照片并且我只需要屏幕截图。为了检测屏幕截图,我想将图像尺寸与屏幕尺寸相匹配。
var userScreenshots: PHFetchResult!
let screenWidth = view.bounds.size.width * 2
let screenHeight = view.bounds.size.height * 2
let options = PHFetchOptions()
// Following line needs to be changed —>
options.predicate = NSPredicate(format: "(pixelWidth & %d) != 0 || (pixelHeight & %d) != 0", screenWidth, screenHeight)
options.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]
userScreenshots = PHAsset.fetchAssetsWithOptions(options)
崩溃:
2015-06-22 23:00:24.540 Altershot[95046:24515142] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unsupported predicate in fetch options: pixelWidth & 0 != 0'
请解释如何正确定义这个谓词。
【问题讨论】:
-
你想在你的谓词中选择什么?
-
只有特定宽度和高度的照片。
-
(pixelWidth == %d AND pixelHeight == %d) ?而且我建议您不要使用“* 2”,而是使用比例因子(iPhone 6 Plus 不应该通过,我认为 iPad mini 也是)
-
@Larme 代码不再崩溃,但结果为空。我会接受规模建议,谢谢。
-
"(pixelWidth == %d AND pixelHeight == %d) OR (pixelWidth == %d AND pixelHeight == %d)" screenWidth, screenHeight , screenHeight, screenWidth?可能是方向问题。
标签: ios swift photosframework