CALayer+Extension.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // CALayer+Extension.h
  3. // iOSFastWorkStateClientOC
  4. //
  5. // Created by 翟玉磊 on 2018/11/26.
  6. // Copyright © 2018 翟玉磊. All rights reserved.
  7. //
  8. #import <QuartzCore/QuartzCore.h>
  9. typedef NS_ENUM(NSInteger, OscillatoryAnimationType) {
  10. OscillatoryAnimationBeBigger,
  11. OscillatoryAnimationBeSmaller,
  12. };
  13. @interface CALayer (Extension)<CAAnimationDelegate>
  14. @property (nonatomic) CGFloat left; ///< Shortcut for frame.origin.x.
  15. @property (nonatomic) CGFloat top; ///< Shortcut for frame.origin.y
  16. @property (nonatomic) CGFloat right; ///< Shortcut for frame.origin.x + frame.size.width
  17. @property (nonatomic) CGFloat bottom; ///< Shortcut for frame.origin.y + frame.size.height
  18. @property (nonatomic) CGFloat width; ///< Shortcut for frame.size.width.
  19. @property (nonatomic) CGFloat height; ///< Shortcut for frame.size.height.
  20. @property (nonatomic) CGPoint center; ///< Shortcut for center.
  21. @property (nonatomic) CGFloat centerX; ///< Shortcut for center.x
  22. @property (nonatomic) CGFloat centerY; ///< Shortcut for center.y
  23. @property (nonatomic) CGPoint origin; ///< Shortcut for frame.origin.
  24. @property (nonatomic, getter=frameSize, setter=setFrameSize:) CGSize size; ///< Shortcut for frame.size.
  25. @property (nonatomic) CGFloat transformRotation; ///< key path "tranform.rotation"
  26. @property (nonatomic) CGFloat transformRotationX; ///< key path "tranform.rotation.x"
  27. @property (nonatomic) CGFloat transformRotationY; ///< key path "tranform.rotation.y"
  28. @property (nonatomic) CGFloat transformRotationZ; ///< key path "tranform.rotation.z"
  29. @property (nonatomic) CGFloat transformScale; ///< key path "tranform.scale"
  30. @property (nonatomic) CGFloat transformScaleX; ///< key path "tranform.scale.x"
  31. @property (nonatomic) CGFloat transformScaleY; ///< key path "tranform.scale.y"
  32. @property (nonatomic) CGFloat transformScaleZ; ///< key path "tranform.scale.z"
  33. @property (nonatomic) CGFloat transformTranslationX; ///< key path "tranform.translation.x"
  34. @property (nonatomic) CGFloat transformTranslationY; ///< key path "tranform.translation.y"
  35. @property (nonatomic) CGFloat transformTranslationZ; ///< key path "tranform.translation.z"
  36. /**
  37. Take snapshot without transform, image's size equals to bounds.
  38. 截短图
  39. */
  40. - (nullable UIImage *)snapshotImage;
  41. /**
  42. Take snapshot without transform, PDF's page size equals to bounds.
  43. */
  44. - (nullable NSData *)snapshotPDF;
  45. /**
  46. Shortcut to set the layer's shadow
  47. 设置阴影
  48. @param color Shadow Color
  49. @param offset Shadow offset
  50. @param radius Shadow radius
  51. */
  52. - (void)setLayerShadow:(UIColor *_Nullable)color offset:(CGSize)offset radius:(CGFloat)radius;
  53. /**
  54. Remove all sublayers.
  55. 移除所有子sublayers
  56. */
  57. - (void)removeAllSublayers;
  58. /**
  59. Shortcut for transform.m34, -1/1000 is a good value.
  60. It should be set before other transform shortcut.
  61. */
  62. @property (nonatomic) CGFloat transformDepth;
  63. /**
  64. Add a fade animation to layer's contents when the contents is changed.
  65. 添加阴影动画
  66. @param duration Animation duration
  67. @param curve Animation curve.
  68. */
  69. - (void)addFadeAnimationWithDuration:(NSTimeInterval)duration curve:(UIViewAnimationCurve)curve;
  70. /**
  71. Cancel fade animation which is added with "-addFadeAnimationWithDuration:curve:".
  72. */
  73. - (void)removePreviousFadeAnimation;
  74. /**
  75. Add a spring animation to layer's contents when the contents is changed.
  76. 添加弹簧动画
  77. @param keyPath Animation keyPath
  78. @param duration Animation duration
  79. @param curve Animation curve.
  80. */
  81. - (void)addSpringAnimationWithKeyPath:(NSString *_Nullable)keyPath toPoint:(CGPoint)point duration:(NSTimeInterval)duration curve:(UIViewAnimationCurve)curve;
  82. // 设置border
  83. - (void)setBorderColor:(UIColor *_Nullable)borderColor borderWidth:(CGFloat)borderWidth cornerRadius:(CGFloat)cornerRadius;
  84. /**
  85. Add mask with roundedrect
  86. 添加弹簧动画
  87. @param rect RoundedRect
  88. @param corners RoundingCorners
  89. @param cornerRadii cornerRadii
  90. */
  91. - (void)addMaskWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii;
  92. - (void)showScaleAnimationWithRepeatCount:(float)repeatCount;
  93. - (void)showOscillatoryAnimationWithType:(OscillatoryAnimationType)type;
  94. @end