CALayer+YYAdd.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. /**
  14. Provides extensions for `CALayer`.
  15. */
  16. @interface CALayer (YYAdd)
  17. /**
  18. Take snapshot without transform, image's size equals to bounds.
  19. */
  20. - (UIImage *)snapshotImage;
  21. /**
  22. Take snapshot without transform, PDF's page size equals to bounds.
  23. */
  24. - (NSData *)snapshotPDF;
  25. /**
  26. Shortcut to set the layer's shadow
  27. @param color Shadow Color
  28. @param offset Shadow offset
  29. @param radius Shadow radius
  30. */
  31. - (void)setLayerShadow:(UIColor*)color offset:(CGSize)offset radius:(CGFloat)radius;
  32. /**
  33. Remove all sublayers.
  34. */
  35. - (void)removeAllSublayers;
  36. @property (nonatomic) CGFloat left; ///< Shortcut for frame.origin.x.
  37. @property (nonatomic) CGFloat top; ///< Shortcut for frame.origin.y
  38. @property (nonatomic) CGFloat right; ///< Shortcut for frame.origin.x + frame.size.width
  39. @property (nonatomic) CGFloat bottom; ///< Shortcut for frame.origin.y + frame.size.height
  40. @property (nonatomic) CGFloat width; ///< Shortcut for frame.size.width.
  41. @property (nonatomic) CGFloat height; ///< Shortcut for frame.size.height.
  42. @property (nonatomic) CGPoint center; ///< Shortcut for center.
  43. @property (nonatomic) CGFloat centerX; ///< Shortcut for center.x
  44. @property (nonatomic) CGFloat centerY; ///< Shortcut for center.y
  45. @property (nonatomic) CGPoint origin; ///< Shortcut for frame.origin.
  46. @property (nonatomic, getter=frameSize, setter=setFrameSize:) CGSize size; ///< Shortcut for frame.size.
  47. @property (nonatomic) CGFloat transformRotation; ///< key path "tranform.rotation"
  48. @property (nonatomic) CGFloat transformRotationX; ///< key path "tranform.rotation.x"
  49. @property (nonatomic) CGFloat transformRotationY; ///< key path "tranform.rotation.y"
  50. @property (nonatomic) CGFloat transformRotationZ; ///< key path "tranform.rotation.z"
  51. @property (nonatomic) CGFloat transformScale; ///< key path "tranform.scale"
  52. @property (nonatomic) CGFloat transformScaleX; ///< key path "tranform.scale.x"
  53. @property (nonatomic) CGFloat transformScaleY; ///< key path "tranform.scale.y"
  54. @property (nonatomic) CGFloat transformScaleZ; ///< key path "tranform.scale.z"
  55. @property (nonatomic) CGFloat transformTranslationX; ///< key path "tranform.translation.x"
  56. @property (nonatomic) CGFloat transformTranslationY; ///< key path "tranform.translation.y"
  57. @property (nonatomic) CGFloat transformTranslationZ; ///< key path "tranform.translation.z"
  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, assign) CGFloat transformDepth;
  63. /**
  64. Add a fade animation to layer's contents when the contents is changed.
  65. @param duration Animation duration
  66. @param curve Animation curve.
  67. */
  68. - (void)addFadeAnimationWithDuration:(NSTimeInterval)duration curve:(UIViewAnimationCurve)curve;
  69. /**
  70. Cancel fade animation which is added with "-addFadeAnimationWithDuration:curve:".
  71. */
  72. - (void)removePreviousFadeAnimation;
  73. @end