gpt4 book ai didi

ios - 如何在加载时更改 CropRect?

转载 作者:行者123 更新时间:2023-11-29 02:44:16 24 4
gpt4 key购买 nike

我在 this link 中找到了一个有用的库,它可以处理裁剪图像.我只想将它与一个 cropRect 一起使用,即 ratio = 3.0f/4.0f; 而不是选择它们。我在 PECropViewControllerviewDidApper 方法中添加了以下代码:

CGFloat ratio = 3.0f / 4.0f;
CGRect cropRect = self.cropView.cropRect;
CGFloat width = CGRectGetWidth(cropRect);
cropRect.size = CGSizeMake(width, width * ratio);
self.cropView.cropRect = cropRect;

但它不起作用。当我按下 Edit 按钮时,有 (void)constrain:(id)sender 方法起作用。如果我用这种方法编写上面的代码,效果很好。这是代码:

(void)constrain:(id)sender
{
CGFloat ratio = 3.0f / 4.0f;
CGRect cropRect = self.cropView.cropRect;
CGFloat width = CGRectGetWidth(cropRect);
cropRect.size = CGSizeMake(width, width * ratio);
self.cropView.cropRect = cropRect;
return;
{

问题是当 croppingView 出现时,我无法更改 cropRectratio

最佳答案

如果有人正在寻找这个问题的解决方案,我找到了。我刚刚更改了 PECropView 中的 cropAspectRatio:

- (void)setupImageView
{
CGRect cropRect = AVMakeRectWithAspectRatioInsideRect(self.image.size, self.insetRect);
self.scrollView.frame = cropRect;
self.scrollView.contentSize = cropRect.size;

self.zoomingView = [[UIView alloc] initWithFrame:self.scrollView.bounds];
self.zoomingView.backgroundColor = [UIColor clearColor];
[self.scrollView addSubview:self.zoomingView];

self.imageView = [[UIImageView alloc] initWithFrame:self.zoomingView.bounds];
self.imageView.backgroundColor = [UIColor clearColor];
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
self.imageView.image = self.image;
[self.zoomingView addSubview:self.imageView];

//i added this line code
self.cropAspectRatio = 4 / 3.0;
}

关于ios - 如何在加载时更改 CropRect?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25337905/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com