Demo app crashes on resize with keepingCropAspectRatio and cropAspectRatio
rajapandians opened this issue · comments
Steps to reproduce:
Set the following values:
controller.cropAspectRatio = 1.0;
controller.keepingCropAspectRatio = YES;
Then Change the following line
[self presentViewController:navigationController animated:YES completion:NULL];
To
[self presentViewController:navigationController animated:NO completion:NULL];
Just changing animated:YES to animated:NO crashes the app
i just trying to debug the issue as found that the CGRect are passed as NaN so its getting crashed.
This affects that when using cropView directly on our own viewcontroller
Anything to fix this up?
Thanks.
Thank you reporting.
I will try to fix the issue. 🙏
Sure. Thanks for the awesome library
@rajapandians It may be fixed by #41. Please check latest master.
@ninjinkun I checked the new code but no luck, still we have this issue.
I also found the issue!
It is because in class PECropView.m the method layoutSubviews excuse before the method setImageCropRect, but the right order should be reverse.
I resolve the issue as follow:
-
(void)viewDidLoad
{
CGRect f = self.view.frame;CGRect cropF = CGRectMake(0, 0, CGRectGetWidth(f), CGRectGetHeight(f) - 44);
cropView = [[PECropView alloc] initWithFrame:cropF];
cropView.image = sourceImage;
[self.view insertSubview:cropView atIndex:0];[NSTimer scheduledTimerWithTimeInterval:.2 target:self selector:@selector(resetScropView) userInfo:nil repeats:NO];
} -
(void)resetScropView
{
CGFloat width = sourceImage.size.width;
CGFloat height = sourceImage.size.height;
CGFloat length = MIN(width, height);
cropView.imageCropRect = CGRectMake((width - length) / 2,
(height - length) / 2,
length,
length);
cropView.keepingCropAspectRatio = YES;
cropView.cropAspectRatio = 1;
}
Thanks @fisherjoe -- I knew there was something wrong with layoutSubviews and the call to setupImageView. I tried your workaround and it works fine.
Although, I would like to see a solution that is baked into the source.