Project address: TFImageBrowser

A convenient picture browser, provides picture resources, can be horizontal view, switch pictures.

use

Use pod Search “TFImageBrowser” — Simple to find the latest version, integrate with Cocoapods.

This project on Github is using example + Image browser code.


Note: To let the image browser and SDWebImage share the cache, open the EnableSDWebImageResolver macro.

#define EnableSDWebImageResolver 1 // EnableSDWebImage to parse images
Copy the code

The switch macro is EnableYYWebImageResolver.


1. Support multiple picture resources

  • The image resource can be a string, such as a network connection address, a local file, or the image name within the MainBundle
  • It can be a system resource type, for examplePHAssertandALAssert
  • It can also beUIImagetype

Various image resource types can be mixed together in the same group, that is, the same browsing image can contain web images, album images, etc.

2. It can be shared with other image cache libraries

If you have an image that is downloaded and cached using SDWebImage, once you pass the URL of the image to the image browser, you can use the shared cache by specifying the sdWebImage-related parser instead of having to download again.

There is also a YYWebImage parser by default, which can share image resources with YYWebImage.

3. The original iCloud image is displayed

When the album space optimization is enabled, the photos in the album will be saved to iCloud, leaving only blurry thumbnails.

When viewing album image resources using TFImageBrowser, if the image is in iCloud, it will be downloaded and displayed as a large image in the same way as other web resources.

4. Support double click to zoom in and view

  • Double click to enlarge the picture to view, and according to the click position, enlarge the click area.
  • Click on the image to close the Image browser
  • Long click on the picture callback event
  • Supports vertical and horizontal rotation

5. Bring your own cutscenes

[self showImageBrowser:_browserVC fromRect:CGRectMake(40, 400, 30, ShowType (200) transitionDuration: 0.25 f TFImageBrowerShowTypePresentDismiss)];Copy the code

Using the method above to display the image browser uses a specific cutscene: a small area on the right zooms in to full screen, just as it does when the system album clicks to see a larger image.

6. A progress bar can be configured

For the image resources loaded from the network, the download progress will be continuously fed back. If the progress bar is configured, the progress will be displayed.

UIProgressView *progressBar = [[UIProgressView alloc] initWithFrame:CGRectMake([UIScreen Width / 2.0-50, [UIScreen mainScreen].bounds. Size. Height /2.0, 100, 20)]; _browserVC.progressView = progressBar;Copy the code

The progress bar only needs to be of UIView type and implement the setProgress: method. So you can customize any progress bar provided to the image browser.

The library also provides a circular progress bar implementation with custom size, color, ring width, and so on. Such as:

About the Project Framework

The body is photo browser TFImageBrowserImageView TFImageBrowserViewController and display each picture.

Since image resources can be described in many different ways, the protocol TFImageBrowserImageUri is defined. Each class implementing this protocol can describe one image resource type, and the existing types are the three mentioned above.

The data provided to imageBrowser is NSArray< ID

> *allImages, which are abstract types, and then how each image resource gets the image data is up to the parser. The parser is the type that implements the protocol TFImageUriDataResolver. Its function is to receive an imageUri, and then the parser is responsible for parsing this resource into A UIImage, which is displayed in the callback interface.

Then TFImageBrowserImageDisplayTool come from the image data to the display logic, such as the request a thumbnail or a larger version, whether to display the progress bar, etc.