Woo*_*Kim 6 iphone objective-c uiscrollview uiimageview ios
我正在进行一个定制'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
Run Code Online (Sandbox Code Playgroud)
这是结果.

黑色区域是contentInset区域.
但是,如果我捏这个scrollView进行放大,就会发生一些事情.

我想我必须做些什么
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
Run Code Online (Sandbox Code Playgroud)
动态调整contentInset.我怎样才能做到这一点?请给我一些帮助:)
我希望有人回答这个问题,我很伤心,因为事实并非如此。
但感谢上帝,我解决了这个问题。
在
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
Run Code Online (Sandbox Code Playgroud)
使用zoomScale动态调整contentInset。我只是Lanscape mode为了测试而实现,但Portrait mode方式完全相同。
// adjust contentInset
CGFloat increasingZoomScale = (scrollView.zoomScale == 1) ? 0 : (-1 * (1 - scrollView.zoomScale));
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);
// implement at `Landscape` mode first
if (self.photoCropOrientation == SKPhotoCropOrientationPortrait) {
}else{
// get scaledFrameHeight because it's `Landscape` crop mode
CGFloat increasingFrameHeight = scrollView.frame.size.height * increasingZoomScale;
self.contentInset = UIEdgeInsetsMake(difference/2 - increasingFrameHeight/2, 0, difference/2 - increasingFrameHeight/2, 0);
}
Run Code Online (Sandbox Code Playgroud)
砰。这是屏幕截图。

| 归档时间: |
|
| 查看次数: |
3933 次 |
| 最近记录: |