简体   繁体   English

如何让TTPhotoViewController显示UIImage?

[英]How to get TTPhotoViewController to display a UIImage?

I have a UIImage that I want to display with TTPhotoViewController, but TTPhotoViewController does not take a UIImage as an argument. 我有一个UIImage,我想用TTPhotoViewController显示,但TTPhotoViewController不会将UIImage作为参数。 It does take a TTPhoto as an argument, so I'm wondering if there is a way to convert a UIImage to a TTPhoto or if there is any other way to get the TTPhotoViewController to display my UIImage other than setting the defaultImage, which didn't work too good. 它确实需要一个TTPhoto作为参数,所以我想知道是否有办法将UIImage转换为TTPhoto,或者是否有任何其他方法可以让TTPhotoViewController显示我的UIImage,而不是设置defaultImage,它没有'工作得太好了。

I use a little hack to do it: 我用一点点黑客来做:

NSString *url = [[TTURLCache sharedCache] createUniqueTemporaryURL];    
[[TTURLCache sharedCache] storeImage:baseImage forURL:url force:YES];

PEPhotoViewController *album=[[[PEPhotoViewController alloc] initWithImageURL:url] autorelease];

You need to create an object that conforms to the TTPhotoSource protocol, implementing the required methods. 您需要创建一个符合TTPhotoSource协议的对象,并实现所需的方法。 Then you need to populate that data source with objects that conform to the TTPhoto protocol. 然后,您需要使用符合TTPhoto协议的对象填充该数据源。

You should then be able to set the photo source property on the TTPhotoViewController and Three20's magic should work. 然后,您应该能够在TTPhotoViewController上设置照片源属性,并且Three20的魔法应该可以工作。

In my own experience I've only used this framework with URLs to images and downloading them using Three20's TTModel framework. 根据我自己的经验,我只使用这个框架的URL到图像并使用Three20的TTModel框架下载它们。 I'm not entirely sure how this affects loading images locally. 我不完全确定这会如何影响本地加载图像。

You can give local path to the library. 您可以提供库的本地路径。 Should be bandle:// or documents:// . 应该是bandle://documents:// Take a look at the TTCatalog example source. 看一下TTCatalog示例源代码。

just set self.defaultImage to your image. 只需将self.defaultImage设置为您的图像。 It should work. 它应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM