objective c - Constant crop aspect ratio using PEPhotoCropEditor library in iOS -
i'm using pephotocropeditor library in 1 of ios project. able having constant aspect ratio (1:1) following code.
- (void)openeditor { pecropviewcontroller *controller = [[pecropviewcontroller alloc] init]; controller.delegate = self; controller.image = self.imageview.image; uiimage *image = self.imageview.image; cgfloat width = image.size.width; cgfloat height = image.size.height; cgfloat length = min(width, height); cgrectmake(cgfloat x, cgfloat y, cgfloat width, cgfloat height) controller.imagecroprect = cgrectmake((width - length) / 2, (height - length) / 2, length, length); // restricted square aspect ratio controller.keepingcropaspectratio = yes; controller.cropaspectratio = 1.0; uinavigationcontroller *navigationcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:controller]; [self presentviewcontroller:navigationcontroller animated:yes completion:null]; }
but needed have aspect ratio (height:width) of (1:3) instead of (1:1).
controller.cropaspectratio = 1.0f / 3.0f;
i tried above , nothing happened. still having same aspect ratio. change below code too.
controller.imagecroprect = cgrectmake((width - length) / 2, (height - length) / 2, length * 3, length);
again nothing happened. after commenting above hard coded value below.
controller.imagecroprect = cgrectmake(0.0f, 0.0f, 300.0f, 100.0f);
then cropping area displayed correctly when resizing aria lead destroy crop aspect ratio (1:3)
any idea how remain aspect ratio (1:3) till editing process complete?
set in viewdidappear in pecropviewcontroller.m
self.cropaspectratio = 1.0f; self.keepingcropaspectratio = yes;
and pass value function setkeepingaspectratio in pecroprectview.m
- (void)setkeepingaspectratio:(bool)keepingaspectratio { _keepingaspectratio = keepingaspectratio; if (self.keepingaspectratio) { cgfloat width = cgrectgetwidth(self.bounds); cgfloat height = cgrectgetheight(self.bounds); self.fixedaspectratio = your_fixed_aspect_ratio_value;//fminf(width / height, height / width); } }
you expected result.
Comments
Post a Comment