CALayer+YYAdd.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // CALayer+YYAdd.h
  3. // YYKit <https://github.com/ibireme/YYKit>
  4. //
  5. // Created by ibireme on 14/5/10.
  6. // Copyright (c) 2015 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import <UIKit/UIKit.h>
  12. #import <QuartzCore/QuartzCore.h>
  13. NS_ASSUME_NONNULL_BEGIN
  14. /**
  15. Provides extensions for `CALayer`.
  16. */
  17. @interface CALayer (YYAdd)
  18. /**
  19. Take snapshot without transform, image's size equals to bounds.
  20. */
  21. - (nullable UIImage *)snapshotImage;
  22. /**
  23. Take snapshot without transform, PDF's page size equals to bounds.
  24. */
  25. - (nullable NSData *)snapshotPDF;
  26. /**
  27. Shortcut to set the layer's shadow
  28. @param color Shadow Color
  29. @param offset Shadow offset
  30. @param radius Shadow radius
  31. */
  32. - (void)setLayerShadow:(UIColor*)color offset:(CGSize)offset radius:(CGFloat)radius;
  33. /**
  34. Remove all sublayers.
  35. */
  36. - (void)removeAllSublayers;
  37. @property (nonatomic) CGFloat left; ///< Shortcut for frame.origin.x.
  38. @property (nonatomic) CGFloat top; ///< Shortcut for frame.origin.y
  39. @property (nonatomic) CGFloat right; ///< Shortcut for frame.origin.x + frame.size.width
  40. @property (nonatomic) CGFloat bottom; ///< Shortcut for frame.origin.y + frame.size.height
  41. @property (nonatomic) CGFloat width; ///< Shortcut for frame.size.width.
  42. @property (nonatomic) CGFloat height; ///< Shortcut for frame.size.height.
  43. @property (nonatomic) CGPoint center; ///< Shortcut for center.
  44. @property (nonatomic) CGFloat centerX; ///< Shortcut for center.x
  45. @property (nonatomic) CGFloat centerY; ///< Shortcut for center.y
  46. @property (nonatomic) CGPoint origin; ///< Shortcut for frame.origin.
  47. @property (nonatomic, getter=frameSize, setter=setFrameSize:) CGSize size; ///< Shortcut for frame.size.
  48. @property (nonatomic) CGFloat transformRotation; ///< key path "tranform.rotation"
  49. @property (nonatomic) CGFloat transformRotationX; ///< key path "tranform.rotation.x"
  50. @property (nonatomic) CGFloat transformRotationY; ///< key path "tranform.rotation.y"
  51. @property (nonatomic) CGFloat transformRotationZ; ///< key path "tranform.rotation.z"
  52. @property (nonatomic) CGFloat transformScale; ///< key path "tranform.scale"
  53. @property (nonatomic) CGFloat transformScaleX; ///< key path "tranform.scale.x"
  54. @property (nonatomic) CGFloat transformScaleY; ///< key path "tranform.scale.y"
  55. @property (nonatomic) CGFloat transformScaleZ; ///< key path "tranform.scale.z"
  56. @property (nonatomic) CGFloat transformTranslationX; ///< key path "tranform.translation.x"
  57. @property (nonatomic) CGFloat transformTranslationY; ///< key path "tranform.translation.y"
  58. @property (nonatomic) CGFloat transformTranslationZ; ///< key path "tranform.translation.z"
  59. /**
  60. Shortcut for transform.m34, -1/1000 is a good value.
  61. It should be set before other transform shortcut.
  62. */
  63. @property (nonatomic) CGFloat transformDepth;
  64. /**
  65. Wrapper for `contentsGravity` property.
  66. */
  67. @property (nonatomic) UIViewContentMode contentMode;
  68. /**
  69. Add a fade animation to layer's contents when the contents is changed.
  70. @param duration Animation duration
  71. @param curve Animation curve.
  72. */
  73. - (void)addFadeAnimationWithDuration:(NSTimeInterval)duration curve:(UIViewAnimationCurve)curve;
  74. /**
  75. Cancel fade animation which is added with "-addFadeAnimationWithDuration:curve:".
  76. */
  77. - (void)removePreviousFadeAnimation;
  78. @end
  79. NS_ASSUME_NONNULL_END