您的位置:首页 > 移动开发 > IOS开发

iOS解锁界面的"滑动来解锁"闪烁动画效果

2016-06-22 17:11 525 查看
今天在github上看到个库,facebook搞的,非常简单的API就能完成你们看到的效果:每天解锁iPhone,看到底部“滑动来解锁”这个效果:

示例DEMO:

先导入#import "FBShimmeringView.h"类:

- (void)viewDidLoad {
[super viewDidLoad];

//生成FBShimmeringView对象
FBShimmeringView *view1 = [[FBShimmeringView alloc] initWithFrame:CGRectMake(100, 20, 300, 100)];
view1.shimmering = YES; //闪烁效果
view1.shimmeringOpacity = 1; //闪烁视图透明度
view1.shimmeringDirection = FBShimmerDirectionRight;//闪烁动画方向
view1.shimmeringBeginFadeDuration = .5;//持续时间
view1.shimmeringPauseDuration = 0.6;//闪烁暂停时间
view1.shimmeringAnimationOpacity = .1;//闪烁动画时透明度
view1.shimmeringSpeed = 200;//闪烁速度
[self.view addSubview:view1];

UILabel *label = [[UILabel alloc] initWithFrame:view1.frame];
label.text = @"》滑 动 解 锁 》";
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont boldSystemFontOfSize:20];
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor whiteColor];
view1.contentView = label;

}
给大家加了所有字段的中文解释,自己测试出来的,可能会有写错误,(借鉴)




//! @abstract Set this to YES to start shimming and NO to stop. Defaults to NO.
//是否闪烁
//@property (nonatomic, assign, readwrite, getter = isShimmering) BOOL shimmering;

//!@abstract The time interval between shimmerings in seconds. Defaults to 0.4.
//两次闪烁之间的间隔
//@property (assign, nonatomic, readwrite) CFTimeInterval shimmeringPauseDuration;

//!@abstract The opacity of the content while it is shimmering. Defaults to 1.0.
//闪烁时动画的透明度 1.0就是原始亮度 0-1之间随意选择
//@property (assign, nonatomic, readwrite) CGFloat shimmeringAnimationOpacity;

//!@abstract The opacity of the content before it is shimmering. Defaults to 0.5.
//闪烁前的透明度,例如默认0.5,那么和上面那个参数对比下,就是0.5-1之间闪烁
//@property (assign, nonatomic, readwrite) CGFloat shimmeringOpacity;

//!@abstract The speed of shimmering, in points per second. Defaults to 230.
//闪烁的速度
//@property (assign, nonatomic, readwrite) CGFloat shimmeringSpeed;

//!@abstract The highlight length of shimmering. Range of [0,1], defaults to 0.33.
//闪烁过去的时候那条线的宽度 0 - 1之间的浮点数切换
//@property (assign, nonatomic, readwrite) CGFloat shimmeringHighlightLength;

//!@abstract @deprecated Same as "shimmeringHighlightLength", just for downward compatibility
//和上面类似
//@property (assign, nonatomic, readwrite, getter = shimmeringHighlightLength, setter = setShimmeringHighlightLength:) CGFloat shimmeringHighlightWidth;

//!@abstract The direction of shimmering animation. Defaults to FBShimmerDirectionRight.
//闪烁的方向,这个枚举有上下左右四个方向
//@property (assign, nonatomic, readwrite) FBShimmerDirection shimmeringDirection;

//!@abstract The duration of the fade used when shimmer begins. Defaults to 0.1.
//开始闪烁的时间间隔
//@property (assign, nonatomic, readwrite) CFTimeInterval shimmeringBeginFadeDuration;

//!@abstract The duration of the fade used when shimmer ends. Defaults to 0.3.
//结束闪烁的时间间隔
//@property (assign, nonatomic, readwrite) CFTimeInterval shimmeringEndFadeDuration;

/**
@abstract The absolute CoreAnimation media time when the shimmer will fade in.
@discussion Only valid after setting {@ref shimmering} to NO.
*/
//闪烁到shimmeringAnimationOpacity的时候fade需要多久
//@property (assign, nonatomic, readonly) CFTimeInterval shimmeringFadeTime;

    
各自属性的默认值是这样的,需要的请自行修改即可

[o

- (instancetype)init  

{  

  self = [super init];  

  if (nil != self) {  

    // default configuration  

    _shimmeringPauseDuration = 0.4;  

    _shimmeringSpeed = 230.0;  

    _shimmeringHighlightLength = 1.0;  

    _shimmeringAnimationOpacity = 0.5;  

    _shimmeringOpacity = 1.0;  

    _shimmeringDirection = FBShimmerDirectionRight;  

    _shimmeringBeginFadeDuration = 0.1;  

    _shimmeringEndFadeDuration = 0.3;  

  }  

  return self;  

}


就这么简单,设置自己喜欢的属性就好了,跑起来看看,效果已经给大家配好了,也可以自行尝试,肯定很酷炫

参考资料:
iOS之iPhone解锁界面的"滑动来解锁"闪烁动画效果,好奇的赶紧进来取走,别看了,说的就是你0.0

FBShimmering的gitHub地址
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息