[翻译] Shimmer

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上的加载条中使用了的。

[翻译] Shimmer

 

Usage

To use Shimmer, create a FBShimmeringView or FBShimmeringLayer and add your content. To start shimmering, set the shimmering property to YES.

使用Shimmer,创建FBshimmeringView或者FBShimmeringLayer然后添加里的content。你可以设置shimmering属性来出发闪烁效果。

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:

  1. Shimmer is available as Shimmer in Cocoapods.
  2. Manually add the files into your Xcode project. Slightly simpler, but updates are also manual.

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属性来触发闪烁特效,与WWDC talk上描述的效果类似。Shimmer使用了CoreAnimation的time特性来流畅的过度开始与结束的动画效果。

 

附录:

[翻译] Shimmer

注意,这个shiimer是可以和自家产品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];

    

    // 制造形状的layer

    CAShapeLayer *layer = [CAShapeLayer layer];

    layer.lineWidth = 1.f;

    layer.strokeColor = [UIColor redColor].CGColor;

    showLayer.contentLayer = layer;

    

    // 贝塞尔曲线(创建一个圆)

    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 100)

                                                        radius:98.f

                                                    startAngle:DEGREES(0)

                                                      endAngle:DEGREES(360)

                                                     clockwise:YES];

    // 获取path

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

 

 

 

你可能感兴趣的:(翻译)