Update the README and example to the latest version, show SDAnimatedImageView usage
This commit is contained in:
parent
22d83f764e
commit
97ff5b05da
|
@ -1,11 +1,11 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
|
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
|
||||||
<device id="retina4_7" orientation="portrait">
|
<device id="retina4_7" orientation="portrait">
|
||||||
<adaptation id="fullscreen"/>
|
<adaptation id="fullscreen"/>
|
||||||
</device>
|
</device>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<deployment identifier="iOS"/>
|
<deployment identifier="iOS"/>
|
||||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
|
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
|
||||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
||||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -17,23 +17,9 @@
|
||||||
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
|
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<subviews>
|
|
||||||
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="RFu-Oe-4ia">
|
|
||||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
|
||||||
</imageView>
|
|
||||||
</subviews>
|
|
||||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||||
<constraints>
|
|
||||||
<constraint firstItem="RFu-Oe-4ia" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="Sdh-Zp-74C"/>
|
|
||||||
<constraint firstItem="RFu-Oe-4ia" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="U5c-8s-Ehx"/>
|
|
||||||
<constraint firstItem="RFu-Oe-4ia" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="eH6-kl-Kl9"/>
|
|
||||||
<constraint firstItem="RFu-Oe-4ia" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="l7U-la-kh4"/>
|
|
||||||
</constraints>
|
|
||||||
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
|
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
|
||||||
</view>
|
</view>
|
||||||
<connections>
|
|
||||||
<outlet property="imageView" destination="RFu-Oe-4ia" id="IV9-xD-bYt"/>
|
|
||||||
</connections>
|
|
||||||
</viewController>
|
</viewController>
|
||||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
||||||
</objects>
|
</objects>
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
#import <SDWebImage/SDWebImage.h>
|
#import <SDWebImage/SDWebImage.h>
|
||||||
|
|
||||||
@interface ViewController ()
|
@interface ViewController ()
|
||||||
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
|
@property (nonatomic, strong) UIImageView *imageView1;
|
||||||
|
@property (nonatomic, strong) SDAnimatedImageView *imageView2;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -23,9 +24,40 @@
|
||||||
|
|
||||||
[[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]];
|
[[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]];
|
||||||
|
|
||||||
[self.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://littlesvr.ca/apng/images/SteamEngine.webp"]];
|
self.imageView1 = [UIImageView new];
|
||||||
|
self.imageView1.contentMode = UIViewContentModeScaleAspectFit;
|
||||||
|
[self.view addSubview:self.imageView1];
|
||||||
|
|
||||||
|
self.imageView2 = [SDAnimatedImageView new];
|
||||||
|
self.imageView2.contentMode = UIViewContentModeScaleAspectFit;
|
||||||
|
[self.view addSubview:self.imageView2];
|
||||||
|
|
||||||
|
NSURL *staticWebPURL = [NSURL URLWithString:@"https://www.gstatic.com/webp/gallery/2.webp"];
|
||||||
|
NSURL *animatedWebPURL = [NSURL URLWithString:@"http://littlesvr.ca/apng/images/world-cup-2014-42.webp"];
|
||||||
|
|
||||||
|
[self.imageView1 sd_setImageWithURL:staticWebPURL completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||||
|
if (image) {
|
||||||
|
NSLog(@"%@", @"Static WebP load success");
|
||||||
|
}
|
||||||
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||||
|
NSData *webpData = [image sd_imageDataAsFormat:SDImageFormatWebP];
|
||||||
|
if (webpData) {
|
||||||
|
NSLog(@"%@", @"WebP encoding success");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}];
|
||||||
|
[self.imageView2 sd_setImageWithURL:animatedWebPURL completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||||
|
if (image) {
|
||||||
|
NSLog(@"%@", @"Animated WebP load success");
|
||||||
|
}
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)viewWillLayoutSubviews {
|
||||||
|
[super viewWillLayoutSubviews];
|
||||||
|
self.imageView1.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height / 2);
|
||||||
|
self.imageView2.frame = CGRectMake(0, self.view.bounds.size.height / 2, self.view.bounds.size.width, self.view.bounds.size.height / 2);
|
||||||
|
}
|
||||||
|
|
||||||
- (void)didReceiveMemoryWarning {
|
- (void)didReceiveMemoryWarning {
|
||||||
[super didReceiveMemoryWarning];
|
[super didReceiveMemoryWarning];
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 939 KiB |
48
README.md
48
README.md
|
@ -6,7 +6,9 @@
|
||||||
[![Platform](https://img.shields.io/cocoapods/p/SDWebImageWebPCoder.svg?style=flat)](http://cocoapods.org/pods/SDWebImageWebPCoder)
|
[![Platform](https://img.shields.io/cocoapods/p/SDWebImageWebPCoder.svg?style=flat)](http://cocoapods.org/pods/SDWebImageWebPCoder)
|
||||||
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/SDWebImage/SDWebImageWebPCoder)
|
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/SDWebImage/SDWebImageWebPCoder)
|
||||||
|
|
||||||
Starting with the SDWebImage 5.0 version, we moved the [libwebp](https://github.com/webmproject/libwebp) support code from the Core Repo to this stand-alone repo.
|
Starting with the SDWebImage 5.0 version, we moved the WebP support code and [libwebp](https://github.com/webmproject/libwebp) from the Core Repo to this stand-alone repo.
|
||||||
|
|
||||||
|
SDWebImageWebPCoder supports both WebP decoding and encoding, for Static WebP or Animated WebP as well.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
|
@ -35,13 +37,38 @@ github "SDWebImage/SDWebImageWebPCoder"
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```objective-c
|
+ Objective-C
|
||||||
SDImageWebPCoder *webPCoder = [SDImageWebPCoder sharedCoder];
|
|
||||||
[[SDWebImageCodersManager sharedInstance] addCoder:webPCoder];
|
|
||||||
|
|
||||||
|
```objective-c
|
||||||
|
// Add coder
|
||||||
|
SDImageWebPCoder *webPCoder = [SDImageWebPCoder sharedCoder];
|
||||||
|
[[SDImageCodersManager sharedManager] addCoder:webPCoder];
|
||||||
|
|
||||||
|
// WebP image loading
|
||||||
UIImageView *imageView;
|
UIImageView *imageView;
|
||||||
NSURL *WebPURL = ...;
|
NSURL *webpURL;
|
||||||
[imageView sd_setImageWithURL:WebPURL];
|
[imageView sd_setImageWithURL:webpURL];
|
||||||
|
|
||||||
|
// WebP image encoding
|
||||||
|
UIImage *image;
|
||||||
|
NSData *webpData = [UIImage sd_imageDataAsFormat:SDImageFormatWebP];
|
||||||
|
```
|
||||||
|
|
||||||
|
+ Swift
|
||||||
|
|
||||||
|
```swift
|
||||||
|
// Add coder
|
||||||
|
let WebPCoder = SDImageWebPCoder.shared
|
||||||
|
SDImageCodersManager.shared.addCoder(WebPCoder)
|
||||||
|
|
||||||
|
// WebP online image loading
|
||||||
|
let webpURL: URL
|
||||||
|
let imageView: UIImageView
|
||||||
|
imageView.sd_setImage(with: webpURL)
|
||||||
|
|
||||||
|
// WebP image encoding
|
||||||
|
let image: UIImage
|
||||||
|
let webpData = image.sd_imageData(asFormat: .WebP)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
@ -50,10 +77,19 @@ To run the example project, clone the repo, and run `pod install` from the Examp
|
||||||
|
|
||||||
This is a demo to show how to use `WebP` and animated `WebP` images via `SDWebImage`.
|
This is a demo to show how to use `WebP` and animated `WebP` images via `SDWebImage`.
|
||||||
|
|
||||||
|
## Screenshot
|
||||||
|
|
||||||
|
<img src="https://raw.githubusercontent.com/SDWebImage/SDWebImageWebPCoder/master/Example/Screenshot/WebPDemo.png" width="300" />
|
||||||
|
|
||||||
|
These WebP images are from [WebP Gallery](https://developers.google.com/speed/webp/gallery1) and [GIF vs APNG vs WebP](http://littlesvr.ca/apng/gif_apng_webp.html)
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
|
|
||||||
[Bogdan Poplauschi](https://github.com/bpoplauschi)
|
[Bogdan Poplauschi](https://github.com/bpoplauschi)
|
||||||
|
[DreamPiggy](https://github.com/dreampiggy)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
SDWebImageWebPCoder is available under the MIT license. See [the LICENSE file](https://github.com/SDWebImage/SDWebImageWebPCoder/blob/master/LICENSE) for more info.
|
SDWebImageWebPCoder is available under the MIT license. See [the LICENSE file](https://github.com/SDWebImage/SDWebImageWebPCoder/blob/master/LICENSE) for more info.
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue