TOCropViewController.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //
  2. // TOCropViewController.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 TOCropViewController;
  24. ///------------------------------------------------
  25. /// @name Delegate
  26. ///------------------------------------------------
  27. @protocol TOCropViewControllerDelegate <NSObject>
  28. @optional
  29. /**
  30. Called when the user has committed the crop action, and provides just the cropping rectangle
  31. @param cropRect A rectangle indicating the crop region of the image the user chose (In the original image's local co-ordinate space)
  32. */
  33. - (void)cropViewController:(TOCropViewController *)cropViewController didCropImageToRect:(CGRect)cropRect angle:(NSInteger)angle;
  34. /**
  35. Called when the user has committed the crop action, and provides both the original image with crop co-ordinates.
  36. @param image The newly cropped image.
  37. @param cropRect A rectangle indicating the crop region of the image the user chose (In the original image's local co-ordinate space)
  38. */
  39. - (void)cropViewController:(TOCropViewController *)cropViewController didCropToImage:(UIImage *)image withRect:(CGRect)cropRect angle:(NSInteger)angle;
  40. /**
  41. If implemented, when the user hits cancel, or completes a UIActivityViewController operation, this delegate will be called,
  42. giving you a chance to manually dismiss the view controller
  43. */
  44. - (void)cropViewController:(TOCropViewController *)cropViewController didFinishCancelled:(BOOL)cancelled;
  45. @end
  46. @interface TOCropViewController : UIViewController
  47. /**
  48. The original, uncropped image that was passed to this controller.
  49. */
  50. @property (nonatomic, readonly) UIImage *image;
  51. /**
  52. The view controller's delegate that will return the resulting cropped image, as well as crop information
  53. */
  54. @property (nonatomic, weak) id<TOCropViewControllerDelegate> delegate;
  55. /**
  56. If true, when the user hits 'Done', a UIActivityController will appear before the view controller ends
  57. */
  58. @property (nonatomic, assign) BOOL showActivitySheetOnDone;
  59. /**
  60. If performing a transition animation, this block can be used to set up any view states just before the animation begins
  61. */
  62. @property (nonatomic, copy) void (^prepareForTransitionHandler)(void);
  63. /**
  64. If `showActivitySheetOnDone` is true, then these activity items will be supplied to that UIActivityViewController
  65. in addition to the `TOActivityCroppedImageProvider` object.
  66. */
  67. @property (nonatomic, strong) NSArray *activityItems;
  68. /**
  69. If `showActivitySheetOnDone` is true, then you may specify any custom activities your app implements in this array.
  70. If your activity requires access to the cropping information, it can be accessed in the supplied `TOActivityCroppedImageProvider` object
  71. */
  72. @property (nonatomic, strong) NSArray *applicationActivities;
  73. /**
  74. If `showActivitySheetOnDone` is true, then you may expliclty set activities that won't appear in the share sheet here.
  75. */
  76. @property (nonatomic, strong) NSArray *excludedActivityTypes;
  77. ///------------------------------------------------
  78. /// @name Object Creation
  79. ///------------------------------------------------
  80. /**
  81. Creates a new instance of a crop view controller with the supplied image
  82. @param image The image that will be used to crop.
  83. */
  84. - (instancetype)initWithImage:(UIImage *)image;
  85. /**
  86. Play a custom animation of the target image zooming to its position in the crop controller while the background fades in.
  87. If any view configurations need to be done before the animation starts, please do them in `prepareForTransitionHandler`
  88. @param viewController The parent controller that this view controller would be presenting from.
  89. @param frame In the screen's coordinate space, the frame from which the image should animate from.
  90. @param completion A block that is called once the transition animation is completed.
  91. */
  92. - (void)presentAnimatedFromParentViewController:(UIViewController *)viewController fromFrame:(CGRect)frame completion:(void (^)(void))completion;
  93. /**
  94. Play a custom animation of the supplied cropped image zooming out from the cropped frame to the specified frame as the rest of the content fades out.
  95. If any view configurations need to be done before the animation starts, please do them in `prepareForTransitionHandler`
  96. @param viewController The parent controller that this view controller would be presenting from.
  97. @param frame The target frame that the image will animate to
  98. @param completion A block that is called once the transition animation is completed.
  99. */
  100. - (void)dismissAnimatedFromParentViewController:(UIViewController *)viewController withCroppedImage:(UIImage *)image toFrame:(CGRect)frame completion:(void (^)(void))completion;
  101. /**
  102. Play a custom animation of the supplied cropped image zooming out from the cropped frame to the specified frame as the rest of the content fades out.
  103. If any view configurations need to be done before the animation starts, please do them in `prepareForTransitionHandler`
  104. @param viewController The parent controller that this view controller would be presenting from.
  105. @param frame The target frame that the image will animate to
  106. @param completion A block that is called once the transition animation is completed.
  107. */
  108. - (void)dismissAnimatedFromParentViewController:(UIViewController *)viewController toFrame:(CGRect)frame completion:(void (^)(void))completion;
  109. @end