【发布时间】:2013-04-10 14:59:30
【问题描述】:
我正在进行一个自定义 'Move and Scale' Controller 或 UIImagePickerController 的项目。 (imagePickerController.allowsEditing=YES时出现的控制器)
我想在裁剪矩形中crop an UIImage,如下图所示。
我编写了一些代码来设置contentInset。
self.selectedImageView.backgroundColor = [UIColor redColor];
CGRect cropRect = [SKPhotoCropFrameView getCropRectFromOrientation:self.photoCropOrientation];
CGRect aspectFitRect = AVMakeRectWithAspectRatioInsideRect(self.selectedImageView.image.size, self.selectedImageView.frame);
CGFloat difference = fabsf(cropRect.size.height - aspectFitRect.size.height);
self.contentInset = UIEdgeInsetsMake(difference/2, 0, difference/2 + 20, 0); // 20 is status bar height
这是结果。
黑色区域是 contentInset 区域。
但是,如果我捏这个 scrollView 来放大,就会发生一些事情。
我想我必须做点什么
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
动态调整 contentInset。我怎样才能做到这一点?请给我一些帮助:)
【问题讨论】:
-
不是您问题的真正答案,但您的方法与苹果的不同,这就是问题所在。当图像完全缩小时,它们不允许向下滚动,使用捏合手势时不能只放大图像的上部。您要么需要将方法更改为 Apple 使用的方法并限制缩放区域,要么使用一些 UI 元素以编程方式执行缩放,这样您就可以完全控制正在缩放的区域。
-
@Eugene 谢谢你的评论。我认为我的方法与 Apple 的方法完全相同。我模仿默认的 UIImagePickerController。我只想实现默认的 UIImagePickerController 'Move and Scale' 控制器。您能解释一下为什么这与 Apple 的复杂程度不同吗?
标签: iphone ios objective-c uiscrollview uiimageview