先上效果圖:
demo中的一些效果:
1吻育、 cell的一些動畫
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat viewHeight = scrollView.height + scrollView.contentInset.top;
for (MyCell *cell in [self.tableView visibleCells]) {
CGFloat y = cell.centerY - scrollView.contentOffset.y;
CGFloat p = y - viewHeight / 2;
CGFloat scale = cos(p / viewHeight * 0.8) * 0.95;
[UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState animations:^{
cell.webImageView.transform = CGAffineTransformMakeScale(scale, scale);
} completion:NULL];
}
}
2、在gif 加載完成的時候添加點(diǎn)擊tap见间、pan手勢聊闯,點(diǎn)擊動畫以及平移手勢可以觀看動畫的每一幀執(zhí)行過程。使用的是官網(wǎng)demo的一個工具類缤剧。
[YYImageExampleHelper addTapControlToAnimatedImageView:self.webImageView];
[YYImageExampleHelper addPanControlToAnimatedImageView:self.webImageView];
3馅袁、在微信聊天或者一些APP加載Gif(比如百思不得姐)中,拖拽過程中會暫停gif動畫荒辕,在停止拖動的時候可以繼續(xù)動畫汗销。恰好YYWebImage的一個子類YYAnimatedImageView恰好提供了一個這樣的實(shí)現(xiàn):
- (void)stopAnimating {
[super stopAnimating];
[_requestQueue cancelAllOperations];
_link.paused = YES;
self.currentIsPlayingAnimation = NO;
}
- (void)startAnimating {
YYAnimatedImageType type = [self currentImageType];
if (type == YYAnimatedImageTypeImages || type == YYAnimatedImageTypeHighlightedImages) {
NSArray *images = [self imageForType:type];
if (images.count > 0) {
[super startAnimating];
self.currentIsPlayingAnimation = YES;
}
} else {
if (_curAnimatedImage && _link.paused) {
_curLoop = 0;
_loopEnd = NO;
_link.paused = NO;
self.currentIsPlayingAnimation = YES;
}
}
}
我有一句牛批不知當(dāng)講不當(dāng)講,這個庫簡直好用的不行抵窒。(請自行略過....)
好了接下來 附上代碼:
其實(shí)最主要的是是利用下面接口做文章弛针,
- (void)yy_setImageWithURL:(NSURL *)imageURL
placeholder:(UIImage *)placeholder
options:(YYWebImageOptions)options
progress:(YYWebImageProgressBlock)progress
transform:(YYWebImageTransformBlock)transform
completion:(YYWebImageCompletionBlock)completion {
[self yy_setImageWithURL:imageURL
placeholder:placeholder
options:options
manager:nil
progress:progress
transform:transform
completion:completion];
}
接口中有自帶的一些過度動畫,自己可以利用返回的加載進(jìn)度做一些加載動畫李皇。因?yàn)橹皩戇^一個圓形加載動畫就直接用了削茁。如下
我們需要做的就是先展示這個占位圖,同步加載進(jìn)度掉房,加載完成后隱藏即可茧跋。
占位圖在弱網(wǎng) 情況下很明顯,網(wǎng)速太好不容易看得處理卓囚。
補(bǔ)充一個知識點(diǎn)瘾杭,如何在Mac上模擬弱網(wǎng)環(huán)境,限制網(wǎng)速哪亿。
蘋果官方提供了限制系統(tǒng)整體網(wǎng)速的插件粥烁,界面如下:
下載地址:Sign in with your Apple ID**,登錄后搜索 Additional Tools for Xcode 或 Hardware IO Tools for Xcode
(不需要安裝Xcode應(yīng)該也可以運(yùn)行)蝇棉,下載完成后從里面找到Network Link Conditioner
讨阻,雙擊安裝即可。
以上Gif
鏈接均來自YYWebImage
的事例demo
篡殷。
最后附上demo地址 :異步加載Gif的幾個效果