- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
所以我使用 SwipeView 库 ( https://github.com/nicklockwood/SwipeView ) 来显示使用 iOS8 Photos 框架的图像。
但是,当我调用 requestImageForAsset 时,我注意到我得到了两个结果,一个是缩略图大小,另一个是我想要的更大的大小。但是,较大的图像没有及时加载(我理解它称为异步)以返回,因此它返回小图像。
这段代码可能更有意义。
func swipeView(swipeView: SwipeView!, viewForItemAtIndex index: Int, reusingView view: UIView!) -> UIView! {
let asset: PHAsset = self.photosAsset[index] as PHAsset
var imageView: UIImageView!
let screenSize: CGSize = UIScreen.mainScreen().bounds.size
let targetSize = CGSizeMake(screenSize.width, screenSize.height)
var options = PHImageRequestOptions()
// options.deliveryMode = PHImageRequestOptionsDeliveryMode.Opportunistic
options.resizeMode = PHImageRequestOptionsResizeMode.Exact
PHImageManager.defaultManager().requestImageForAsset(asset, targetSize: targetSize, contentMode: .AspectFill, options: options, resultHandler: {(result, info)in
println("huhuhuh")
println(result.size)
println(info)
imageView = UIImageView(image: result)
})
println("setting view)
return imageView
}
这是日志输出:
Enteredhuhuhuh
(33.5,60.0)
SETTING VIEW
huhuhuh
(320.0,568.0)
如您所见,它会在接收到大图像之前返回 ImageView 。我如何让它返回这个更大的图像而不显示缩略图?
谢谢。
最佳答案
读取 PHImageManager
类的 header
If -[PHImageRequestOptions isSynchronous] returns NO (or options is nil), resultHandler may be called 1 or more times. Typically in this case, resultHandler will be called asynchronously on the main thread with the requested results. However, if deliveryMode = PHImageRequestOptionsDeliveryModeOpportunistic, resultHandler may be called synchronously on the calling thread if any image data is immediately available. If the image data returned in this first pass is of insufficient quality, resultHandler will be called again, asychronously on the main thread at a later time with the "correct" results. If the request is cancelled, resultHandler may not be called at all. If -[PHImageRequestOptions isSynchronous] returns YES, resultHandler will be called exactly once, synchronously and on the calling thread. Synchronous requests cannot be cancelled. resultHandler for asynchronous requests, always called on main thread
因此,您要做的是让 resultHandler
被同步
调用
PHImageRequestOptions *option = [PHImageRequestOptions new];
option.synchronous = YES;
[[PHImageManager defaultManager] requestImageForAsset:asset targetSize:target contentMode:PHImageContentModeAspectFill options:option resultHandler:^(UIImage *result, NSDictionary *info) {
//this block will be called synchronously
}];
所以你的 block 将在结束你的方法之前被调用
祝你好运!
关于ios - 照片框架。 requestImageForAsset 返回两个结果。无法设置 ImageView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27670325/
对于某些视频,requestImageForAsset 以 nil 的 UIImage 完成。对于其他视频,它工作正常,我还没有弄清楚为什么。 func createThumbnailForVideo
我正在使用图像选择器库来允许用户从他们的照片库中选择许多图像。它们以 PHAssets 数组的形式返回。然后,我想将所有 PHAssets 转换为 UIImages 并将它们写入应用程序的存储。 目前
在照片框架中,我正在尝试查看使用 PHImageManager 中的 RequestImageFor Asset 方法的教程。 这是一段代码: let asset:PHAsset = self
我有一个 UICollectionView 的问题,我认为我已经缩小到以下区域。问题是,当我在 UICollectionView 上调用重新加载时,会出现闪烁,加载 1 张图像,然后加载正确的图像。几
所以我使用 SwipeView 库 ( https://github.com/nicklockwood/SwipeView ) 来显示使用 iOS8 Photos 框架的图像。 但是,当我调用 req
所以,我遇到了一个奇怪(且令人沮丧)的问题。我正在循环访问图像选择器返回的一组资源: let manager = PHImageManager.defaultManager() let options
我正在使用 Photos 框架在 iOS swift 中处理图像。当我尝试使用 PHImageManager.defaultImanager().requestImageForAsset() 获取图像
我有一个展示照片库图像列表的收藏 View ,在选择时,我想获取最高质量的版本并提供一个 Controller 来裁剪它。 我的收藏 View 的调用工作正常:。 let options = PHIm
我尝试使用方法 requestImageForAsset 获取照片。使用选项: auto options = [PHImageRequestOptions new]; options.resizeMo
大约 10% 的时间 PHImageManager.defaultManager().requestImageForAsset 在第一次返回有效但“降级”的 UIImage 后返回 nil 而不是有效
我已经通读了最新的 iOS8 相框作品,我正在尝试从用户库中获取一些资源来显示。我让用户一次编辑 4 张图像。但正因为如此,我需要压缩图像,否则应用程序会崩溃。 我正在使用 PHImageManage
如问题所述,如果我在任何运行 iOS 9 或更高版本的设备上执行 RequestImageForAsset(在 iPhone 5s、6 和 6s Plus 上试过),当我尝试检索以 1:1 拍摄的照片
我正在尝试使用 UIPageViewController 显示图像,使用来自苹果的示例代码并将其替换为新的照片工具包:PHAsset https://developer.apple.com/libra
我是一名优秀的程序员,十分优秀!