作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 this link 中找到了一个有用的库,它可以处理裁剪图像.我只想将它与一个 cropRect
一起使用,即 ratio = 3.0f/4.0f;
而不是选择它们。我在 PECropViewController
的 viewDidApper
方法中添加了以下代码:
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
出现时,我无法更改 cropRect
的 ratio
。
最佳答案
如果有人正在寻找这个问题的解决方案,我找到了。我刚刚更改了 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/
我在 this link 中找到了一个有用的库,它可以处理裁剪图像.我只想将它与一个 cropRect 一起使用,即 ratio = 3.0f/4.0f; 而不是选择它们。我在 PECropViewC
我想在拍摄后裁剪图像或从库中选择图像。如何更改 UIImagePickerController 裁剪区域的可显示框架大小。 我附上了一张图片以了解我的问题当我捕获或选择图像时,我得到红色方框。实际上我
我是一名优秀的程序员,十分优秀!