[翻译] Shimmer
Shimmer
shimmer是facebook出的一個用來顯示微光閃爍特效的動畫庫,facebook出的,必屬精品,你懂的。
?
Shimmer is an easy way to add a shimmering effect to any view in your app. It's useful as an unobtrusive loading indicator.
Shimmer was originally developed to show loading status in?Paper.
Shimmer 能讓你非常容易的添加微光閃爍的特效。你可以在一些不引人注目的指示器上使用。
Shimmer最開始是我在Paper上的加載條中使用了的。
?
Usage
To use Shimmer, create a?FBShimmeringView?or?FBShimmeringLayer?and add your content. To start shimmering, set the?shimmering?property to?YES.
使用Shimmer,創(chuàng)建FBshimmeringView或者FBShimmeringLayer然后添加里的content。你可以設置shimmering屬性來出發(fā)閃爍效果。
An example of making a label shimmer:
以下是簡單的使用示例:
FBShimmeringView *shimmeringView = [[FBShimmeringView alloc] initWithFrame:self.view.bounds]; [self.view addSubview:shimmeringView];UILabel *loadingLabel = [[UILabel alloc] initWithFrame:shimmeringView.bounds]; loadingLabel.textAlignment = NSTextAlignmentCenter; loadingLabel.text = NSLocalizedString(@"Shimmer", nil); shimmeringView.contentView = loadingLabel;// Start shimmering. shimmeringView.shimmering = YES;There's also an example project. In the example, you can swipe horizontally and vertically to try various shimmering parameters, or tap to start or stop shimmering. (To build the example locally, you'll need to openFBShimmering.xcworkpace?rather than the?.xcodeproj.)
下載的工程文件中有demo可以演示。
?
Installation
There are two options:
Shimmer requires iOS 6 or later.
?
How it works
Shimmer uses the?-[CALayer mask]?property to enable shimmering, similar to what's described in John Harper's 2009 WWDC talk (unfortunately no longer online). Shimmer uses CoreAnimation's timing features to smoothly transition "on-beat" when starting and stopping the shimmer.
Shimmer使用了calayer的mask屬性來觸發(fā)閃爍特效,與WWDC talk上描述的效果類似。Shimmer使用了CoreAnimation的time特性來流暢的過度開始與結束的動畫效果。
?
附錄:
注意,這個shiimer是可以和自家產(chǎn)品POP動畫一起使用的.
// // RootViewController.m // // Copyright (c) 2014年 Y.X. All rights reserved. // #import "RootViewController.h" #import "FBShimmeringLayer.h" #import "CAShapeLayer+Circle.h" #import "YXGCD.h" #import "POP.h"@interface RootViewController ()@property (nonatomic, strong) GCDTimer *timer;@end@implementation RootViewController- (void)viewDidLoad {[super viewDidLoad];self.view.backgroundColor = [UIColor blackColor];// 直接使用layer層做動畫FBShimmeringLayer *showLayer = [FBShimmeringLayer new];showLayer.frame = (CGRect){CGPointZero, CGSizeMake(200, 200)};showLayer.position = self.view.center;showLayer.shimmering = YES;showLayer.shimmeringBeginFadeDuration = 0.3;showLayer.shimmeringOpacity = 0.3;showLayer.shimmeringPauseDuration = 0.6f;[self.view.layer addSublayer:showLayer];// 制造形狀的layerCAShapeLayer *layer = [CAShapeLayer layer];layer.lineWidth = 1.f;layer.strokeColor = [UIColor redColor].CGColor;showLayer.contentLayer = layer;// 貝塞爾曲線(創(chuàng)建一個圓)UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 100)radius:98.fstartAngle:DEGREES(0)endAngle:DEGREES(360)clockwise:YES];// 獲取pathlayer.path = path.CGPath;// 設置填充顏色為透明layer.fillColor = [UIColor clearColor].CGColor;// 使用POP動畫_timer = [[GCDTimer alloc] initInQueue:[GCDQueue mainQueue]];[_timer event:^{CGFloat value1 = arc4random()%100/100.f;POPSpringAnimation *strokeAnimationEnd = \[POPSpringAnimation animationWithPropertyNamed:kPOPShapeLayerStrokeEnd];strokeAnimationEnd.toValue = @(value1);strokeAnimationEnd.springBounciness = 12.f;[layer pop_addAnimation:strokeAnimationEnd forKey:@"layerStrokeAnimation"];} timeInterval:1*NSEC_PER_SEC];[_timer start]; }@end?
?
?
總結
以上是生活随笔為你收集整理的[翻译] Shimmer的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: xmpp muc 群聊协议 1
- 下一篇: Android中的进程