FBShimmeringView.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. Copyright (c) 2014-present, Facebook, Inc.
  3. All rights reserved.
  4. This source code is licensed under the BSD-style license found in the
  5. LICENSE file in the root directory of this source tree. An additional grant
  6. of patent rights can be found in the PATENTS file in the same directory.
  7. */
  8. #import "FBShimmeringView.h"
  9. #import "FBShimmeringLayer.h"
  10. #if !__has_feature(objc_arc)
  11. #error This file must be compiled with ARC. Convert your project to ARC or specify the -fobjc-arc flag.
  12. #endif
  13. @implementation FBShimmeringView
  14. + (Class)layerClass
  15. {
  16. return [FBShimmeringLayer class];
  17. }
  18. #define __layer ((FBShimmeringLayer *)self.layer)
  19. #define LAYER_ACCESSOR(accessor, ctype) \
  20. - (ctype)accessor { \
  21. return [__layer accessor]; \
  22. }
  23. #define LAYER_MUTATOR(mutator, ctype) \
  24. - (void)mutator (ctype)value { \
  25. [__layer mutator value]; \
  26. }
  27. #define LAYER_RW_PROPERTY(accessor, mutator, ctype) \
  28. LAYER_ACCESSOR (accessor, ctype) \
  29. LAYER_MUTATOR (mutator, ctype)
  30. LAYER_RW_PROPERTY(isShimmering, setShimmering:, BOOL)
  31. LAYER_RW_PROPERTY(shimmeringPauseDuration, setShimmeringPauseDuration:, CFTimeInterval)
  32. LAYER_RW_PROPERTY(shimmeringAnimationOpacity, setShimmeringAnimationOpacity:, CGFloat)
  33. LAYER_RW_PROPERTY(shimmeringOpacity, setShimmeringOpacity:, CGFloat)
  34. LAYER_RW_PROPERTY(shimmeringSpeed, setShimmeringSpeed:, CGFloat)
  35. LAYER_RW_PROPERTY(shimmeringHighlightLength, setShimmeringHighlightLength:, CGFloat)
  36. LAYER_RW_PROPERTY(shimmeringDirection, setShimmeringDirection:, FBShimmerDirection)
  37. LAYER_ACCESSOR(shimmeringFadeTime, CFTimeInterval)
  38. LAYER_RW_PROPERTY(shimmeringBeginFadeDuration, setShimmeringBeginFadeDuration:, CFTimeInterval)
  39. LAYER_RW_PROPERTY(shimmeringEndFadeDuration, setShimmeringEndFadeDuration:, CFTimeInterval)
  40. - (void)setContentView:(UIView *)contentView
  41. {
  42. if (contentView != _contentView) {
  43. _contentView = contentView;
  44. [self addSubview:contentView];
  45. __layer.contentLayer = contentView.layer;
  46. }
  47. }
  48. @end