@@ -20,6 +20,8 @@ declare class TOCropViewController extends UIViewController {
2020 delegate : any ;
2121 cropView : TOCropView ;
2222 toolbar : TOCropToolbar ;
23+ defaultAspectRatio : any ;
24+ aspectRatioLocked : boolean ;
2325 public setAspectRatioLocked ( aspectRatioLocked : boolean ) : void ;
2426 public setRotateButtonHidden ( rotateButtonHidden : boolean ) : void ;
2527 public setRotateClockwiseButtonHidden ( rotateClockwiseButtonHidden : boolean ) : void ;
@@ -115,21 +117,22 @@ export class ImageCropper {
115117 if ( image . ios ) {
116118 var viewController = TOCropViewController . alloc ( ) . initWithImage ( image . ios ) ;
117119 var delegate = TOCropViewControllerDelegateImpl . initWithOwner ( new WeakRef ( viewController ) ) ;
118-
119120 delegate . initResolveReject ( resolve , reject ) ;
120-
121121 CFRetain ( delegate ) ;
122122 viewController . delegate = delegate ;
123-
124123 var page = frame . topmost ( ) . ios . controller ;
124+ if ( _options . lockSquare ) {
125+ viewController . defaultAspectRatio = 1 ;
126+ viewController . aspectRatioLocked = true ; // The crop box is locked to the aspect ratio and can't be resized away from it
127+ }
125128 page . presentViewControllerAnimatedCompletion ( viewController , true , function ( ) {
126- //Set Fixed Crop Size
127- if ( _options && _options . width && _options . height ) {
128- var gcd = _that . _gcd ( _options . width , _options . height ) ;
129+ if ( _options ) {
130+ if ( _options . width && _options . height ) {
131+ var gcd = _that . _gcd ( _options . width , _options . height ) ;
132+ viewController . toolbar . clampButtonHidden = true ;
133+ viewController . cropView . setAspectLockEnabledWithAspectRatioAnimated ( CGSizeMake ( _options . width / gcd , _options . height / gcd ) , false ) ;
134+ }
129135
130- viewController . toolbar . clampButtonHidden = true ;
131- // viewController.toolbar.setNeedsLayout();
132- viewController . cropView . setAspectLockEnabledWithAspectRatioAnimated ( CGSizeMake ( _options . width / gcd , _options . height / gcd ) , false ) ;
133136 }
134137 } ) ;
135138 }
0 commit comments