CALayer+YYAdd.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. Shortcut to set the layer's shadow
  23. @param color Shadow Color
  24. @param offset Shadow offset
  25. @param radius Shadow radius
  26. */
  27. - (void)setLayerShadow:(UIColor*)color offset:(CGSize)offset radius:(CGFloat)radius;
  28. /**
  29. Remove all sublayers.
  30. */
  31. - (void)removeAllSublayers;
  32. @property (nonatomic) CGFloat left; ///< Shortcut for frame.origin.x.
  33. @property (nonatomic) CGFloat top; ///< Shortcut for frame.origin.y
  34. @property (nonatomic) CGFloat right; ///< Shortcut for frame.origin.x + frame.size.width
  35. @property (nonatomic) CGFloat bottom; ///< Shortcut for frame.origin.y + frame.size.height
  36. @property (nonatomic) CGFloat width; ///< Shortcut for frame.size.width.
  37. @property (nonatomic) CGFloat height; ///< Shortcut for frame.size.height.
  38. @property (nonatomic) CGPoint center; ///< Shortcut for center.
  39. @property (nonatomic) CGFloat centerX; ///< Shortcut for center.x
  40. @property (nonatomic) CGFloat centerY; ///< Shortcut for center.y
  41. @property (nonatomic) CGPoint origin; ///< Shortcut for frame.origin.
  42. @property (nonatomic, getter=frameSize, setter=setFrameSize:) CGSize size; ///< Shortcut for frame.size.
  43. @property (nonatomic) CGFloat transformRotation; ///< key path "tranform.rotation"
  44. @property (nonatomic) CGFloat transformRotationX; ///< key path "tranform.rotation.x"
  45. @property (nonatomic) CGFloat transformRotationY; ///< key path "tranform.rotation.y"
  46. @property (nonatomic) CGFloat transformRotationZ; ///< key path "tranform.rotation.z"
  47. @property (nonatomic) CGFloat transformScale; ///< key path "tranform.scale"
  48. @property (nonatomic) CGFloat transformScaleX; ///< key path "tranform.scale.x"
  49. @property (nonatomic) CGFloat transformScaleY; ///< key path "tranform.scale.y"
  50. @property (nonatomic) CGFloat transformScaleZ; ///< key path "tranform.scale.z"
  51. @property (nonatomic) CGFloat transformTranslationX; ///< key path "tranform.translation.x"
  52. @property (nonatomic) CGFloat transformTranslationY; ///< key path "tranform.translation.y"
  53. @property (nonatomic) CGFloat transformTranslationZ; ///< key path "tranform.translation.z"
  54. /**
  55. Shortcut for transform.m34, -1/1000 is a good value.
  56. It should be set before other transform shortcut.
  57. */
  58. @property (nonatomic, assign) CGFloat transformDepth;
  59. /**
  60. Add a fade animation to layer's contents when the contents is changed.
  61. @param duration Animation duration
  62. @param curve Animation curve.
  63. */
  64. - (void)addFadeAnimationWithDuration:(NSTimeInterval)duration curve:(UIViewAnimationCurve)curve;
  65. /**
  66. Cancel fade animation which is added with "-addFadeAnimationWithDuration:curve:".
  67. */
  68. - (void)removePreviousFadeAnimation;
  69. @end