diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..fd7f506e --- /dev/null +++ b/.clang-format @@ -0,0 +1,87 @@ +--- +# iOS Objective-C Style Guide +# Based on Apple's coding conventions and common iOS practices + +BasedOnStyle: LLVM + +# Language specific settings +Language: ObjC + +# Indentation +IndentWidth: 4 +TabWidth: 4 +UseTab: Never +ContinuationIndentWidth: 4 + +# Line length +ColumnLimit: 0 + +# Pointer and reference alignment +PointerAlignment: Right +ReferenceAlignment: Right + +# Braces +BreakBeforeBraces: Attach +AllowShortBlocksOnASingleLine: Empty +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: WithoutElse +AllowShortLoopsOnASingleLine: false + +# Method and function formatting +AlignAfterOpenBracket: Align +AllowAllParametersOfDeclarationOnNextLine: false +BinPackParameters: false +BinPackArguments: false + +# Objective-C specific +ObjCBinPackProtocolList: Never +ObjCBlockIndentWidth: 4 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true + +# Spacing +SpaceBeforeParens: ControlStatements +SpaceBeforeAssignmentOperators: true +SpaceAfterCStyleCast: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false + +# Keep things together +KeepEmptyLinesAtTheStartOfBlocks: false +MaxEmptyLinesToKeep: 1 + +# Align consecutive assignments and declarations +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false + +# Comments +ReflowComments: true +SpacesBeforeTrailingComments: 2 + +# Line breaks +AllowShortCaseLabelsOnASingleLine: false +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true + +# Import/Include sorting +SortIncludes: CaseInsensitive +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^<.*\.h>' + Priority: 1 + - Regex: '^<.*>' + Priority: 2 + - Regex: '^"' + Priority: 3 + +# Penalty weights (fine-tuning line breaks) +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 diff --git a/Objective-C/TOCropViewController/Categories/UIImage+CropRotate.m b/Objective-C/TOCropViewController/Categories/UIImage+CropRotate.m index e88e61dd..89e7896e 100644 --- a/Objective-C/TOCropViewController/Categories/UIImage+CropRotate.m +++ b/Objective-C/TOCropViewController/Categories/UIImage+CropRotate.m @@ -24,15 +24,13 @@ @implementation UIImage (CropRotate) -- (BOOL)hasAlpha -{ +- (BOOL)hasAlpha { CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(self.CGImage); return (alphaInfo == kCGImageAlphaFirst || alphaInfo == kCGImageAlphaLast || alphaInfo == kCGImageAlphaPremultipliedFirst || alphaInfo == kCGImageAlphaPremultipliedLast); } -- (UIImage *)croppedImageWithFrame:(CGRect)frame angle:(NSInteger)angle circularClip:(BOOL)circular -{ +- (UIImage *)croppedImageWithFrame:(CGRect)frame angle:(NSInteger)angle circularClip:(BOOL)circular { UIGraphicsImageRendererFormat *format = [UIGraphicsImageRendererFormat new]; format.opaque = !self.hasAlpha && !circular; format.scale = self.scale; @@ -53,7 +51,7 @@ - (UIImage *)croppedImageWithFrame:(CGRect)frame angle:(NSInteger)angle circular // If an angle was supplied, rotate the entire canvas + coordinate space to match if (angle != 0) { // Rotation in radians - CGFloat rotation = angle * (M_PI/180.0f); + CGFloat rotation = angle * (M_PI / 180.0f); // Work out the new bounding size of the canvas after rotation CGRect imageBounds = (CGRect){CGPointZero, self.size}; diff --git a/Objective-C/TOCropViewController/Constants/TOCropViewConstants.h b/Objective-C/TOCropViewController/Constants/TOCropViewConstants.h index 49fe3534..0b75585b 100644 --- a/Objective-C/TOCropViewController/Constants/TOCropViewConstants.h +++ b/Objective-C/TOCropViewController/Constants/TOCropViewConstants.h @@ -26,8 +26,8 @@ The shape of the cropping region of this crop view controller */ typedef NS_ENUM(NSInteger, TOCropViewCroppingStyle) { - TOCropViewCroppingStyleDefault, // The regular, rectangular crop box - TOCropViewCroppingStyleCircular // A fixed, circular crop box + TOCropViewCroppingStyleDefault, // The regular, rectangular crop box + TOCropViewCroppingStyleCircular // A fixed, circular crop box }; /** @@ -35,27 +35,27 @@ typedef NS_ENUM(NSInteger, TOCropViewCroppingStyle) { */ typedef NS_ENUM(NSInteger, TOCropViewControllerToolbarPosition) { TOCropViewControllerToolbarPositionBottom, // Bar is placed along the bottom in portrait - TOCropViewControllerToolbarPositionTop // Bar is placed along the top in portrait (Respects the status bar) + TOCropViewControllerToolbarPositionTop // Bar is placed along the top in portrait (Respects the status bar) }; static inline NSBundle *TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(NSObject *object) { #if SWIFT_PACKAGE - // SPM is supposed to support the keyword SWIFTPM_MODULE_BUNDLE - // but I can't figure out how to make it work, so doing it manually - NSString *bundleName = @"TOCropViewController_TOCropViewController"; + // SPM is supposed to support the keyword SWIFTPM_MODULE_BUNDLE + // but I can't figure out how to make it work, so doing it manually + NSString *bundleName = @"TOCropViewController_TOCropViewController"; #else - NSString *bundleName = @"TOCropViewControllerBundle"; + NSString *bundleName = @"TOCropViewControllerBundle"; #endif NSBundle *resourceBundle = nil; NSBundle *classBundle = [NSBundle bundleForClass:object.class]; NSURL *resourceBundleURL = [classBundle URLForResource:bundleName withExtension:@"bundle"]; if (resourceBundleURL) { resourceBundle = [[NSBundle alloc] initWithURL:resourceBundleURL]; - #ifndef NDEBUG - if (resourceBundle == nil) { - @throw [[NSException alloc] initWithName:@"BundleAccessor" reason:[NSString stringWithFormat:@"unable to find bundle named %@", bundleName] userInfo:nil]; - } - #endif +#ifndef NDEBUG + if (resourceBundle == nil) { + @throw [[NSException alloc] initWithName:@"BundleAccessor" reason:[NSString stringWithFormat:@"unable to find bundle named %@", bundleName] userInfo:nil]; + } +#endif } else { resourceBundle = classBundle; } diff --git a/Objective-C/TOCropViewController/Models/TOActivityCroppedImageProvider.m b/Objective-C/TOCropViewController/Models/TOActivityCroppedImageProvider.m index 04314054..3786c789 100644 --- a/Objective-C/TOCropViewController/Models/TOActivityCroppedImageProvider.m +++ b/Objective-C/TOCropViewController/Models/TOActivityCroppedImageProvider.m @@ -21,6 +21,7 @@ // IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #import "TOActivityCroppedImageProvider.h" + #import "UIImage+CropRotate.h" @interface TOActivityCroppedImageProvider () @@ -36,38 +37,34 @@ @interface TOActivityCroppedImageProvider () @implementation TOActivityCroppedImageProvider -- (instancetype)initWithImage:(UIImage *)image cropFrame:(CGRect)cropFrame angle:(NSInteger)angle circular:(BOOL)circular -{ +- (instancetype)initWithImage:(UIImage *)image cropFrame:(CGRect)cropFrame angle:(NSInteger)angle circular:(BOOL)circular { if (self = [super initWithPlaceholderItem:[UIImage new]]) { _image = image; _cropFrame = cropFrame; _angle = angle; _circular = circular; } - + return self; } #pragma mark - UIActivity Protocols - -- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController -{ +- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController { return [[UIImage alloc] init]; } -- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType -{ +- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType { return self.croppedImage; } #pragma mark - Image Generation - -- (id)item -{ - //If the user didn't touch the image, just forward along the original +- (id)item { + // If the user didn't touch the image, just forward along the original if (self.angle == 0 && CGRectEqualToRect(self.cropFrame, (CGRect){CGPointZero, self.image.size})) { self.croppedImage = self.image; return self.croppedImage; } - + UIImage *image = [self.image croppedImageWithFrame:self.cropFrame angle:self.angle circularClip:self.circular]; self.croppedImage = image; return self.croppedImage; diff --git a/Objective-C/TOCropViewController/Models/TOCropViewControllerAspectRatioPreset.m b/Objective-C/TOCropViewController/Models/TOCropViewControllerAspectRatioPreset.m index 19fae63a..a12c92de 100644 --- a/Objective-C/TOCropViewController/Models/TOCropViewControllerAspectRatioPreset.m +++ b/Objective-C/TOCropViewController/Models/TOCropViewControllerAspectRatioPreset.m @@ -37,8 +37,7 @@ @interface TOCropViewControllerAspectRatioPreset () @implementation TOCropViewControllerAspectRatioPreset -- (instancetype)initWithSize:(CGSize)size title:(NSString *)title -{ +- (instancetype)initWithSize:(CGSize)size title:(NSString *)title { self = [super init]; if (self) { _size = size; @@ -58,37 +57,49 @@ - (BOOL)isEqual:(id)object { return CGSizeEqualToSize(self.size, other.size) && [self.title isEqualToString:other.title]; } -+ (NSArray *)portraitPresets -{ ++ (NSArray *)portraitPresets { TOCropViewControllerAspectRatioPreset *object = [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero title:@"Original"]; - NSBundle *resourceBundle = TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(object); + NSBundle *resourceBundle = TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(object); return @[ - [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero title:NSLocalizedStringFromTableInBundle(@"Original", @"TOCropViewControllerLocalizable", resourceBundle, nil)], - [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(1.0f, 1.0f) title:NSLocalizedStringFromTableInBundle(@"Square", @"TOCropViewControllerLocalizable", resourceBundle, nil)], - [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(2.0f, 3.0f) title:@"2:3"], - [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 5.0f) title:@"3:5"], - [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 4.0f) title:@"3:4"], - [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(4.0f, 5.0f) title:@"4:5"], - [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 7.0f) title:@"5:7"], - [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(9.0f, 16.0f) title:@"9:16"], + [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero + title:NSLocalizedStringFromTableInBundle(@"Original", @"TOCropViewControllerLocalizable", resourceBundle, nil)], + [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(1.0f, 1.0f) + title:NSLocalizedStringFromTableInBundle(@"Square", @"TOCropViewControllerLocalizable", resourceBundle, nil)], + [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(2.0f, 3.0f) + title:@"2:3"], + [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 5.0f) + title:@"3:5"], + [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 4.0f) + title:@"3:4"], + [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(4.0f, 5.0f) + title:@"4:5"], + [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 7.0f) + title:@"5:7"], + [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(9.0f, 16.0f) + title:@"9:16"], ]; } -+ (NSArray *)landscapePresets -{ ++ (NSArray *)landscapePresets { TOCropViewControllerAspectRatioPreset *object = [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero title:@"Original"]; - NSBundle *resourceBundle = TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(object); + NSBundle *resourceBundle = TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(object); return @[ - [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero title:NSLocalizedStringFromTableInBundle(@"Original", @"TOCropViewControllerLocalizable", resourceBundle, nil)], - [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(1.0f, 1.0f) title:NSLocalizedStringFromTableInBundle(@"Square", @"TOCropViewControllerLocalizable", resourceBundle, nil)], - [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 2.0f) title:@"3:2"], - [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 3.0f) title:@"5:3"], - [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(4.0f, 3.0f) title:@"4:3"], - [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 4.0f) title:@"5:4"], - [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(7.0f, 5.0f) title:@"7:5"], - [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(16.0f, 9.0f) title:@"16:9"], + [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero + title:NSLocalizedStringFromTableInBundle(@"Original", @"TOCropViewControllerLocalizable", resourceBundle, nil)], + [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(1.0f, 1.0f) + title:NSLocalizedStringFromTableInBundle(@"Square", @"TOCropViewControllerLocalizable", resourceBundle, nil)], + [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 2.0f) + title:@"3:2"], + [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 3.0f) + title:@"5:3"], + [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(4.0f, 3.0f) + title:@"4:3"], + [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 4.0f) + title:@"5:4"], + [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(7.0f, 5.0f) + title:@"7:5"], + [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(16.0f, 9.0f) + title:@"16:9"], ]; } @end - - diff --git a/Objective-C/TOCropViewController/Models/TOCropViewControllerTransitioning.h b/Objective-C/TOCropViewController/Models/TOCropViewControllerTransitioning.h index 1a2ac61a..1bdf1c27 100644 --- a/Objective-C/TOCropViewController/Models/TOCropViewControllerTransitioning.h +++ b/Objective-C/TOCropViewController/Models/TOCropViewControllerTransitioning.h @@ -28,8 +28,8 @@ NS_ASSUME_NONNULL_BEGIN @interface TOCropViewControllerTransitioning : NSObject /* State Tracking */ -@property (nonatomic, assign) BOOL isDismissing; // Whether this animation is presenting or dismissing -@property (nullable, nonatomic, strong) UIImage *image; // The image that will be used in this animation +@property (nonatomic, assign) BOOL isDismissing; // Whether this animation is presenting or dismissing +@property (nullable, nonatomic, strong) UIImage *image; // The image that will be used in this animation /* Destination/Origin points */ @property (nullable, nonatomic, strong) UIView *fromView; // The origin view who's frame the image will be animated from diff --git a/Objective-C/TOCropViewController/Models/TOCropViewControllerTransitioning.m b/Objective-C/TOCropViewController/Models/TOCropViewControllerTransitioning.m index d7068c82..fc5b7ca9 100644 --- a/Objective-C/TOCropViewController/Models/TOCropViewControllerTransitioning.m +++ b/Objective-C/TOCropViewController/Models/TOCropViewControllerTransitioning.m @@ -21,62 +21,59 @@ // IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #import "TOCropViewControllerTransitioning.h" + #import @implementation TOCropViewControllerTransitioning -- (NSTimeInterval)transitionDuration:(id )transitionContext -{ +- (NSTimeInterval)transitionDuration:(id)transitionContext { return 0.45f; } -- (void)animateTransition:(id )transitionContext -{ +- (void)animateTransition:(id)transitionContext { // Get the master view where the animation takes place UIView *containerView = [transitionContext containerView]; - + // Get the origin/destination view controllers UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; - + // Work out which one is the crop view controller UIViewController *cropViewController = (self.isDismissing == NO) ? toViewController : fromViewController; UIViewController *previousController = (self.isDismissing == NO) ? fromViewController : toViewController; - + // Just in case, match up the frame sizes cropViewController.view.frame = containerView.bounds; if (self.isDismissing) { previousController.view.frame = containerView.bounds; } - + // Add the view layers beforehand as this will trigger the initial sets of layouts if (self.isDismissing == NO) { [containerView addSubview:cropViewController.view]; - //Force a relayout now that the view is in the view hierarchy (so things like the safe area insets are now valid)] + // Force a relayout now that the view is in the view hierarchy (so things like the safe area insets are now valid)] [cropViewController.view setNeedsLayout]; [cropViewController.view layoutIfNeeded]; [cropViewController viewDidLayoutSubviews]; - } - else { + } else { [containerView insertSubview:previousController.view belowSubview:cropViewController.view]; } - + // Perform any last UI updates now so we can potentially factor them into our calculations, but after // the container views have been set up if (self.prepareForTransitionHandler) { self.prepareForTransitionHandler(); } - + // If origin/destination views were supplied, use them to supplant the // frames if (!self.isDismissing && self.fromView) { self.fromFrame = [self.fromView.superview convertRect:self.fromView.frame toView:containerView]; - } - else if (self.isDismissing && self.toView) { + } else if (self.isDismissing && self.toView) { self.toFrame = [self.toView.superview convertRect:self.toView.frame toView:containerView]; } - + UIImageView *imageView = nil; if ((self.isDismissing && !CGRectIsEmpty(self.toFrame)) || (!self.isDismissing && !CGRectIsEmpty(self.fromFrame))) { imageView = [[UIImageView alloc] initWithImage:self.image]; @@ -84,30 +81,39 @@ - (void)animateTransition:(id )transitionC imageView.accessibilityIgnoresInvertColors = YES; [containerView addSubview:imageView]; } - + cropViewController.view.alpha = (self.isDismissing ? 1.0f : 0.0f); if (imageView) { - [UIView animateWithDuration:[self transitionDuration:transitionContext] delay:0.0f usingSpringWithDamping:1.0f initialSpringVelocity:0.7f options:0 animations:^{ - imageView.frame = self.toFrame; - } completion:^(BOOL complete) { - [UIView animateWithDuration:0.25f animations:^{ - imageView.alpha = 0.0f; - }completion:^(BOOL complete) { - [imageView removeFromSuperview]; + [UIView animateWithDuration:[self transitionDuration:transitionContext] + delay:0.0f + usingSpringWithDamping:1.0f + initialSpringVelocity:0.7f + options:0 + animations:^{ + imageView.frame = self.toFrame; + } + completion:^(BOOL complete) { + [UIView animateWithDuration:0.25f + animations:^{ + imageView.alpha = 0.0f; + } + completion:^(BOOL complete) { + [imageView removeFromSuperview]; + }]; }]; - }]; } - - [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ - cropViewController.view.alpha = (self.isDismissing ? 0.0f : 1.0f); - } completion:^(BOOL complete) { - [self reset]; - [transitionContext completeTransition:![transitionContext transitionWasCancelled]]; - }]; + + [UIView animateWithDuration:[self transitionDuration:transitionContext] + animations:^{ + cropViewController.view.alpha = (self.isDismissing ? 0.0f : 1.0f); + } + completion:^(BOOL complete) { + [self reset]; + [transitionContext completeTransition:![transitionContext transitionWasCancelled]]; + }]; } -- (void)reset -{ +- (void)reset { self.image = nil; self.toView = nil; self.fromView = nil; diff --git a/Objective-C/TOCropViewController/Models/TOCroppedImageAttributes.m b/Objective-C/TOCropViewController/Models/TOCroppedImageAttributes.m index 56eb2461..fe1aff39 100644 --- a/Objective-C/TOCropViewController/Models/TOCroppedImageAttributes.m +++ b/Objective-C/TOCropViewController/Models/TOCroppedImageAttributes.m @@ -32,14 +32,13 @@ @interface TOCroppedImageAttributes () @implementation TOCroppedImageAttributes -- (instancetype)initWithCroppedFrame:(CGRect)croppedFrame angle:(NSInteger)angle originalImageSize:(CGSize)originalSize -{ +- (instancetype)initWithCroppedFrame:(CGRect)croppedFrame angle:(NSInteger)angle originalImageSize:(CGSize)originalSize { if (self = [super init]) { _angle = angle; _croppedFrame = croppedFrame; _originalImageSize = originalSize; } - + return self; } diff --git a/Objective-C/TOCropViewController/TOCropViewController.h b/Objective-C/TOCropViewController/TOCropViewController.h old mode 100755 new mode 100644 index 5067ac9e..b894d569 --- a/Objective-C/TOCropViewController/TOCropViewController.h +++ b/Objective-C/TOCropViewController/TOCropViewController.h @@ -23,15 +23,15 @@ #import #if !__has_include() +#import "TOCropToolbar.h" +#import "TOCropView.h" #import "TOCropViewConstants.h" #import "TOCropViewControllerAspectRatioPreset.h" -#import "TOCropView.h" -#import "TOCropToolbar.h" #else +#import +#import #import #import -#import -#import #endif @class TOCropViewController; @@ -44,7 +44,7 @@ @optional /** - Called when the user has committed the crop action, and provides + Called when the user has committed the crop action, and provides just the cropping rectangle. @param cropRect A rectangle indicating the crop region of the image the user chose (In the original image's local co-ordinate space) @@ -55,36 +55,38 @@ angle:(NSInteger)angle; /** - Called when the user has committed the crop action, and provides + Called when the user has committed the crop action, and provides both the original image with crop co-ordinates. - + @param image The newly cropped image. @param cropRect A rectangle indicating the crop region of the image the user chose (In the original image's local co-ordinate space) @param angle The angle of the image when it was cropped */ - (void)cropViewController:(nonnull TOCropViewController *)cropViewController - didCropToImage:(nonnull UIImage *)image withRect:(CGRect)cropRect + didCropToImage:(nonnull UIImage *)image + withRect:(CGRect)cropRect angle:(NSInteger)angle; /** If the cropping style is set to circular, implementing this delegate will return a circle-cropped version of the selected image, as well as it's cropping co-ordinates - + @param image The newly cropped image, clipped to a circle shape @param cropRect A rectangle indicating the crop region of the image the user chose (In the original image's local co-ordinate space) @param angle The angle of the image when it was cropped */ - (void)cropViewController:(nonnull TOCropViewController *)cropViewController - didCropToCircularImage:(nonnull UIImage *)image withRect:(CGRect)cropRect + didCropToCircularImage:(nonnull UIImage *)image + withRect:(CGRect)cropRect angle:(NSInteger)angle; /** - If implemented, when the user hits cancel, or completes a + If implemented, when the user hits cancel, or completes a UIActivityViewController operation, this delegate will be called, giving you a chance to manually dismiss the view controller @param cancelled Whether a cropping action was actually performed, or if the user explicitly hit 'Cancel' - + */ - (void)cropViewController:(nonnull TOCropViewController *)cropViewController didFinishCancelled:(BOOL)cancelled; @@ -121,10 +123,10 @@ */ @property (nonnull, nonatomic, strong, readonly) TOCropView *cropView; -/** +/** In the coordinate space of the image itself, the region that is currently being highlighted by the crop box. - + This property can be set before the controller is presented to have the image 'restored' to a previous cropping layout. */ @@ -133,8 +135,8 @@ /** The angle in which the image is rotated in the crop view. This can only be in 90 degree increments (eg, 0, 90, 180, 270). - - This property can be set before the controller is presented to have + + This property can be set before the controller is presented to have the image 'restored' to a previous cropping layout. */ @property (nonatomic, assign) NSInteger angle; @@ -200,28 +202,28 @@ If true, a custom aspect ratio is set, and the aspectRatioLockEnabled is set to YES, the crop box will swap it's dimensions depending on portrait or landscape sized images. This value also controls whether the dimensions can swap when the image is rotated. - + Default is NO. */ @property (nonatomic, assign) BOOL aspectRatioLockDimensionSwapEnabled; /** If true, while it can still be resized, the crop box will be locked to its current aspect ratio. - + If this is set to YES, and `resetAspectRatioEnabled` is set to NO, then the aspect ratio button will automatically be hidden from the toolbar. - + Default is NO. */ @property (nonatomic, assign) BOOL aspectRatioLockEnabled; -/** +/** If true, tapping the reset button will also reset the aspect ratio back to the image default ratio. Otherwise, the reset will just zoom out to the current aspect ratio. - + If this is set to NO, and `aspectRatioLockEnabled` is set to YES, then the aspect ratio button will automatically be hidden from the toolbar. - + Default is YES */ @property (nonatomic, assign) BOOL resetAspectRatioEnabled; @@ -232,9 +234,9 @@ @property (nonatomic, assign) TOCropViewControllerToolbarPosition toolbarPosition; /** - When disabled, an additional rotation button that rotates the canvas in + When disabled, an additional rotation button that rotates the canvas in 90-degree segments in a clockwise direction is shown in the toolbar. - + Default is NO. */ @property (nonatomic, assign) BOOL rotateClockwiseButtonHidden; @@ -247,9 +249,9 @@ @property (nonatomic, assign) BOOL hidesNavigationBar; /** - When enabled, hides the rotation button, as well as the alternative rotation + When enabled, hides the rotation button, as well as the alternative rotation button visible when `showClockwiseRotationButton` is set to YES. - + Default is NO. */ @property (nonatomic, assign) BOOL rotateButtonsHidden; @@ -262,7 +264,7 @@ @property (nonatomic, assign) BOOL resetButtonHidden; /** When enabled, hides the 'Aspect Ratio Picker' button on the toolbar. - + Default is NO. */ @property (nonatomic, assign) BOOL aspectRatioPickerButtonHidden; @@ -286,26 +288,25 @@ Default is NO. */ -@property (nonatomic, assign) BOOL reverseContentLayout -; +@property (nonatomic, assign) BOOL reverseContentLayout; -/** - If `showActivitySheetOnDone` is true, then these activity items will - be supplied to that UIActivityViewController in addition to the +/** + If `showActivitySheetOnDone` is true, then these activity items will + be supplied to that UIActivityViewController in addition to the `TOActivityCroppedImageProvider` object. */ @property (nullable, nonatomic, strong) NSArray *activityItems; /** - If `showActivitySheetOnDone` is true, then you may specify any - custom activities your app implements in this array. If your activity requires - access to the cropping information, it can be accessed in the supplied + If `showActivitySheetOnDone` is true, then you may specify any + custom activities your app implements in this array. If your activity requires + access to the cropping information, it can be accessed in the supplied `TOActivityCroppedImageProvider` object */ @property (nullable, nonatomic, strong) NSArray *applicationActivities; /** - If `showActivitySheetOnDone` is true, then you may expliclty + If `showActivitySheetOnDone` is true, then you may expliclty set activities that won't appear in the share sheet here. */ @property (nullable, nonatomic, strong) NSArray *excludedActivityTypes; @@ -326,7 +327,7 @@ /** Called when the user has committed the crop action, and provides just the cropping rectangle. - + @param cropRect A rectangle indicating the crop region of the image the user chose (In the original image's local co-ordinate space) @param angle The angle of the image when it was cropped @@ -336,25 +337,24 @@ /** Called when the user has committed the crop action, and provides both the cropped image with crop co-ordinates. - + @param image The newly cropped image. @param cropRect A rectangle indicating the crop region of the image the user chose (In the original image's local co-ordinate space) @param angle The angle of the image when it was cropped */ -@property (nullable, nonatomic, strong) void (^onDidCropToRect)(UIImage* _Nonnull image, CGRect cropRect, NSInteger angle); +@property (nullable, nonatomic, strong) void (^onDidCropToRect)(UIImage *_Nonnull image, CGRect cropRect, NSInteger angle); /** If the cropping style is set to circular, this block will return a circle-cropped version of the selected image, as well as it's cropping co-ordinates - + @param image The newly cropped image, clipped to a circle shape @param cropRect A rectangle indicating the crop region of the image the user chose (In the original image's local co-ordinate space) @param angle The angle of the image when it was cropped */ -@property (nullable, nonatomic, strong) void (^onDidCropToCircleImage)(UIImage* _Nonnull image, CGRect cropRect, NSInteger angle); - +@property (nullable, nonatomic, strong) void (^onDidCropToCircleImage)(UIImage *_Nonnull image, CGRect cropRect, NSInteger angle); ///------------------------------------------------ /// @name Object Creation @@ -362,14 +362,14 @@ /** Creates a new instance of a crop view controller with the supplied image - + @param image The image that will be used to crop. */ - (nonnull instancetype)initWithImage:(nonnull UIImage *)image NS_SWIFT_NAME(init(image:)); -/** +/** Creates a new instance of a crop view controller with the supplied image and cropping style - + @param style The cropping style that will be used with this view controller (eg, rectangular, or circular) @param image The image that will be cropped */ @@ -385,10 +385,10 @@ */ - (void)resetCropViewLayout; -/** +/** Set the aspect ratio to be one of the available preset options. These presets have specific behaviour such as swapping their dimensions depending on portrait or landscape sized images. - + @param aspectRatioPreset The aspect ratio preset @param animated Whether the transition to the aspect ratio is animated */ @@ -396,8 +396,8 @@ /** Play a custom animation of the target image zooming to its position in - the crop controller while the background fades in. - + the crop controller while the background fades in. + @param viewController The parent controller that this view controller would be presenting from. @param fromView A view that's frame will be used as the origin for this animation. Optional if `fromFrame` has a value. @param fromFrame In the screen's coordinate space, the frame from which the image should animate from. Optional if `fromView` has a value. @@ -412,11 +412,11 @@ /** Play a custom animation of the target image zooming to its position in - the crop controller while the background fades in. Additionally, if you're + the crop controller while the background fades in. Additionally, if you're 'restoring' to a previous crop setup, this method lets you provide a previously cropped copy of the image, and the previous crop settings to transition back to where the user would have left off. - + @param viewController The parent controller that this view controller would be presenting from. @param image The previously cropped image that can be used in the transition animation. @param fromView A view that's frame will be used as the origin for this animation. Optional if `fromFrame` has a value. @@ -439,7 +439,7 @@ 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. If any view configurations need to be done before the animation starts, - + @param viewController The parent controller that this view controller would be presenting from. @param toView A view who's frame will be used to establish the destination frame @param frame The target frame that the image will animate to @@ -456,7 +456,7 @@ 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. If any view configurations need to be done before the animation starts, - + @param viewController The parent controller that this view controller would be presenting from. @param image The resulting 'cropped' image. If supplied, will animate out of the crop box zone. If nil, the default image will entirely zoom out @param toView A view who's frame will be used to establish the destination frame @@ -472,4 +472,3 @@ completion:(nullable void (^)(void))completion NS_SWIFT_NAME(dismissAnimatedFrom(_:croppedImage:toView:toFrame:setup:completion:)); @end - diff --git a/Objective-C/TOCropViewController/TOCropViewController.m b/Objective-C/TOCropViewController/TOCropViewController.m old mode 100755 new mode 100644 index 81532d2b..236c155c --- a/Objective-C/TOCropViewController/TOCropViewController.m +++ b/Objective-C/TOCropViewController/TOCropViewController.m @@ -22,10 +22,10 @@ #import "TOCropViewController.h" -#import "TOCropViewControllerTransitioning.h" #import "TOActivityCroppedImageProvider.h" -#import "UIImage+CropRotate.h" #import "TOCroppedImageAttributes.h" +#import "TOCropViewControllerTransitioning.h" +#import "UIImage+CropRotate.h" static const CGFloat kTOCropViewControllerTitleTopPadding = 14.0f; static const CGFloat kTOCropViewControllerToolbarHeight = 44.0f; @@ -57,9 +57,9 @@ @interface TOCropViewController ()