简体   繁体   中英

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. 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.

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. Then you need to populate that data source with objects that conform to the TTPhoto protocol.

You should then be able to set the photo source property on the TTPhotoViewController and Three20's magic should work.

In my own experience I've only used this framework with URLs to images and downloading them using Three20's TTModel framework. I'm not entirely sure how this affects loading images locally.

You can give local path to the library. Should be bandle:// or documents:// . Take a look at the TTCatalog example source.

just set self.defaultImage to your image. It should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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