本文主要是介绍Shimmer–为应用任意视图添加闪烁效果,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Shimmer,可以给你的应用任意视图添加闪烁效果.它可以用于指示一种加载中的状态.
项目主页:Shimmer
安装
通过CocoaPods安装
pod 'Shimmer', '~> 1.0.2'
手动安装
将Shimmer文件夹中的所有源代码拽入项目中即可.
使用
创建一个 FBShimmeringView或 FBShimmeringLayer对象,并添加内容,即可使用Shimmer.为了开始使用闪烁效果,将属性shimmering设为YES即可.
下面是一个让标签闪烁的例子:
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;
// 开始闪烁.
shimmeringView.shimmering = YES;
FBShimmeringView*shimmeringView=[[FBShimmeringViewalloc]initWithFrame:self.view.bounds];
[self.viewaddSubview:shimmeringView];
UILabel*loadingLabel=[[UILabelalloc]initWithFrame:shimmeringView.bounds];
loadingLabel.textAlignment=NSTextAlignmentCenter;
loadingLabel.text=NSLocalizedString(@"Shimmer",nil);
shimmeringView.contentView=loadingLabel;
// 开始闪烁.
shimmeringView.shimmering=YES;
你可以下载最新的示例工程.点击FBShimmering.xcworkpace运行示例工程后,你可以水平或竖直清扫来查看不同参数下闪烁的效果;也可以轻击来开始或停止闪烁效果.
FBShimmering 协议
FBShimmeringView 或 FBShimmeringLayer均遵循协议,可以很灵活地定制他们的行为:
@protocol FBShimmering
//! @abstract 设置为YES,开始闪烁;设置为NO,停止闪烁.默认NO.
@property (assign,nonatomic, readwrite,getter = isShimmering) BOOL shimmering;
//! @abstract 两次闪烁的时间间隔,单位为秒.默认0.4.
@property (assign,nonatomic, readwrite) CFTimeInterval shimmeringPauseDuration;
//! @abstract 内容闪烁时的透明度.默认 0.5.
@property (assign,nonatomic, readwrite) CGFloat shimmeringAnimationOpacity;
//! @abstract 内容闪烁前的透明度,默认1.0.
@property (assign,nonatomic, readwrite) CGFloat shimmeringOpacity;
//! @abstract 内容闪烁的速度,单位点/秒.默认230.
@property (assign,nonatomic, readwrite) CGFloat shimmeringSpeed;
//! @abstract 闪烁区中高亮显示的范围.取值[0,1],默认1.0.
@property (assign,nonatomic, readwrite) CGFloat shimmeringHighlightLength;
//! @abstract 闪烁动画的方向.默认FBShimmerDirectionRight.
@property (assign,nonatomic, readwrite) FBShimmerDirection shimmeringDirection;
//! @abstract 闪烁开始时的淡出时间.默认0.1.
@property (assign,nonatomic, readwrite) CFTimeInterval shimmeringBeginFadeDuration;
//! @abstract 闪烁结束时的淡出时间.默认0.3.
@property (assign,nonatomic, readwrite) CFTimeInterval shimmeringEndFadeDuration;
/**
@abstract 闪烁渐出时,CoreAnimation的绝对媒体时间.
@discussion 只在设置 {@ref shimmering}为NO时有效.
*/
@property (assign,nonatomic, readonly) CFTimeInterval shimmeringFadeTime;
/**
@abstract 闪烁简要开始时,CoreAnimation的绝对媒体时间.
@discussion 只在设置 {@ref shimmering}为YES时有效.
*/
@property (assign,nonatomic) CFTimeInterval shimmeringBeginTime;
@end
@protocolFBShimmering
//! @abstract 设置为YES,开始闪烁;设置为NO,停止闪烁.默认NO.
@property(assign,nonatomic,readwrite,getter=isShimmering)BOOLshimmering;
//! @abstract 两次闪烁的时间间隔,单位为秒.默认0.4.
@property(assign,nonatomic,readwrite)CFTimeIntervalshimmeringPauseDuration;
//! @abstract 内容闪烁时的透明度.默认 0.5.
@property(assign,nonatomic,readwrite)CGFloatshimmeringAnimationOpacity;
//! @abstract 内容闪烁前的透明度,默认1.0.
@property(assign,nonatomic,readwrite)CGFloatshimmeringOpacity;
//! @abstract 内容闪烁的速度,单位点/秒.默认230.
@property(assign,nonatomic,readwrite)CGFloatshimmeringSpeed;
//! @abstract 闪烁区中高亮显示的范围.取值[0,1],默认1.0.
@property(assign,nonatomic,readwrite)CGFloatshimmeringHighlightLength;
//! @abstract 闪烁动画的方向.默认FBShimmerDirectionRight.
@property(assign,nonatomic,readwrite)FBShimmerDirectionshimmeringDirection;
//! @abstract 闪烁开始时的淡出时间.默认0.1.
@property(assign,nonatomic,readwrite)CFTimeIntervalshimmeringBeginFadeDuration;
//! @abstract 闪烁结束时的淡出时间.默认0.3.
@property(assign,nonatomic,readwrite)CFTimeIntervalshimmeringEndFadeDuration;
/**
@abstract 闪烁渐出时,CoreAnimation的绝对媒体时间.
@discussion 只在设置 {@ref shimmering}为NO时有效.
*/
@property(assign,nonatomic,readonly)CFTimeIntervalshimmeringFadeTime;
/**
@abstract 闪烁简要开始时,CoreAnimation的绝对媒体时间.
@discussion 只在设置 {@ref shimmering}为YES时有效.
*/
@property(assign,nonatomic)CFTimeIntervalshimmeringBeginTime;
@end
这篇关于Shimmer–为应用任意视图添加闪烁效果的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!