TOCropView.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // TOCropView.h
  3. //
  4. // Copyright 2015 Timothy Oliver. All rights reserved.
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to
  8. // deal in the Software without restriction, including without limitation the
  9. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. // sell copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20. // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
  21. // IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. #import <UIKit/UIKit.h>
  23. @class TOCropView;
  24. @protocol TOCropViewDelegate <NSObject>
  25. - (void)cropViewDidBecomeResettable:(TOCropView *)cropView;
  26. - (void)cropViewDidBecomeNonResettable:(TOCropView *)cropView;
  27. @end
  28. @interface TOCropView : UIView
  29. /**
  30. The image that the crop view is displaying. This cannot be changed once the crop view is instantiated.
  31. */
  32. @property (nonatomic, strong, readonly) UIImage *image;
  33. /**
  34. A delegate object that receives notifications from the crop view
  35. */
  36. @property (nonatomic, weak) id<TOCropViewDelegate> delegate;
  37. /**
  38. Whether the user has manipulated the crop view to the point where it can be reset
  39. */
  40. @property (nonatomic, readonly) BOOL canReset;
  41. /**
  42. The frame of the cropping box on the crop view
  43. */
  44. @property (nonatomic, readonly) CGRect cropBoxFrame;
  45. /**
  46. The frame of the entire image in the backing scroll view
  47. */
  48. @property (nonatomic, readonly) CGRect imageViewFrame;
  49. /**
  50. Inset the workable region of the crop view in case in order to make space for accessory views
  51. */
  52. @property (nonatomic, assign) UIEdgeInsets cropRegionInsets;
  53. /**
  54. Disable the dynamic translucency in order to smoothly relayout the view
  55. */
  56. @property (nonatomic, assign) BOOL simpleMode;
  57. /**
  58. When the cropping box is locked to its current size
  59. */
  60. @property (nonatomic, assign) BOOL aspectLockEnabled;
  61. /**
  62. True when the height of the crop box is bigger than the width
  63. */
  64. @property (nonatomic, readonly) BOOL cropBoxAspectRatioIsPortrait;
  65. /**
  66. The rotation angle of the crop view (Will always be negative as it rotates in a counter-clockwise direction)
  67. */
  68. @property (nonatomic, assign, readonly) NSInteger angle;
  69. /**
  70. Hide all of the crop elements for transition animations
  71. */
  72. @property (nonatomic, assign) BOOL croppingViewsHidden;
  73. /**
  74. In relation to the coordinate space of the image, the frame that the crop view is focussing on
  75. */
  76. @property (nonatomic, readonly) CGRect croppedImageFrame;
  77. /**
  78. Set the grid overlay graphic to be hidden
  79. */
  80. @property (nonatomic, assign) BOOL gridOverlayHidden;
  81. /**
  82. Create a new instance of the crop view with the supplied image
  83. */
  84. - (instancetype)initWithImage:(UIImage *)image;
  85. /**
  86. When performing large size transitions (eg, orientation rotation),
  87. set simple mode to YES to temporarily graphically heavy effects like translucency.
  88. @param simpleMode Whether simple mode is enabled or not
  89. */
  90. - (void)setSimpleMode:(BOOL)simpleMode animated:(BOOL)animated;
  91. /**
  92. When performing a screen rotation that will change the size of the scroll view, this takes
  93. a snapshot of all of the scroll view data before it gets manipulated by iOS.
  94. Please call this in your view controller, before the rotation animation block is committed.
  95. */
  96. - (void)prepareforRotation;
  97. /**
  98. Performs the realignment of the crop view while the screen is rotating.
  99. Please call this inside your view controller's screen rotation animation block.
  100. */
  101. - (void)performRelayoutForRotation;
  102. /**
  103. Reset the crop box and zoom scale back to the initial layout
  104. @param animated The reset is animated
  105. */
  106. - (void)resetLayoutToDefaultAnimated:(BOOL)animated;
  107. /**
  108. Enables an aspect ratio lock where the crop box will always scale at a specific ratio.
  109. @param aspectRatio The aspect ratio (For example 16:9 is 16.0f/9.0f). Specify 0.0f to lock to the image's original aspect ratio
  110. @param animated Whether the locking effect is animated
  111. */
  112. - (void)setAspectLockEnabledWithAspectRatio:(CGSize)aspectRatio animated:(BOOL)animated;
  113. /**
  114. Rotates the entire canvas to a 90-degree angle
  115. @param angle The angle in which to rotate (May be 0, 90, 180, 270)
  116. @param animated Whether the transition is animated
  117. */
  118. - (void)rotateImageNinetyDegreesAnimated:(BOOL)animated;
  119. /**
  120. Animate the grid overlay graphic to be visible
  121. */
  122. - (void)setGridOverlayHidden:(BOOL)gridOverlayHidden animated:(BOOL)animated;
  123. /**
  124. Animate the cropping component views to become visible
  125. */
  126. - (void)setCroppingViewsHidden:(BOOL)hidden animated:(BOOL)animated;
  127. @end