源码的github地址:
https://github.com/facebook/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;
contentView为FBShimmeringView的subView,setContentView时,添加contentView,获取contentView的layer,并将其强转为FBShimmeringLayer。
Shimmer的效果是由FBShimmeringLayer的subLayer,FBShimmeringMaskLayer(CAGradientLayer的子类)实现。
View和contentView,以及Layer和contentLayer。
/* An object that will receive the CALayer delegate methods defined
* below (for those that it implements). The value of this property is
* not retained. Default value is nil. */
@property(weak) id delegate;
这是一个informal protocol,NSObject的Category,CALayerDelegate。
__bridge
A bridged cast is a C-style cast annotated with one of three keywords:
These casts are required in order to transfer objects in and out of ARC control; see the rationale in the section on conversion of retainable object pointers.
Using a __bridge_retained or __bridge_transfer cast purely to convince ARC to emit an unbalanced retain or release, respectively, is poor form.
官方文档中指出:__bridge兼顾ARC和非ARC两种内存管理系统,两者互不影响,而__bridge_retained和__bridge_transfer会在两种内存管理系统中切换。