我想在我的应用程序中裁剪图像与更新的Instagram相同。 我为它创建了一个演示。 但我在这个演示中遇到了1个问题。 问题是,当我缩放图像然后尝试缩小时,UIImageview缩小了一点点。请检查演示你有我的观点,我试着解释 这是我的演示链接 https://drive.google.com/file/d/0Bw367uJS6w22OTNwTmdCNW5Ta3M/view?usp=sharing
答案 0 :(得分:1)
如果你想要像相机和imagepicker这样的Instagram
,你可以使用这个库吗?答案 1 :(得分:0)
在VPImageCropperViewController
文件中你会找到一个方法
- (void) pinchView:(UIPinchGestureRecognizer *)pinchGestureRecognizer you have to change in that code to work zoom out functionality.
- (void) pinchView:(UIPinchGestureRecognizer *)pinchGestureRecognizer
{
UIView *view = self.showImgView;
if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan || pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) {
view.transform = CGAffineTransformScale(view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);
//pinchGestureRecognizer.scale = 1;
self.showImgView.contentMode=UIViewContentModeScaleAspectFit;
NSLog(@"%f",pinchGestureRecognizer.scale);
// pinchGestureRecognizer.view.transform = CGAffineTransformScale(pinchGestureRecognizer.view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);
// pinchGestureRecognizer.scale = 1;
}
else if (pinchGestureRecognizer.state == UIGestureRecognizerStateEnded) {
NSLog(@"original image size%f",self.originalImage.size.width);
NSLog(@"latestFrame image size%f",self.latestFrame.size.width);
// NSLog(@"original image size%f",self.originalImage.size.width);
// NSLog(@"original image size%f",self.originalImage.size.width);
/* if(pinchGestureRecognizer.scale <= 1.0)
{
// small
CGRect newFrame = self.showImgView.frame;
UIImage *img=[self imageWithImage:self.originalImage scaledToSize:self.cropFrame.size];
newFrame = [self handleScaleOverflow:CGRectMake(0, 0, img.size.width, img.size.height)];
newFrame = [self handleBorderOverflow:CGRectMake(0, 0, img.size.width, img.size.height)];
newFrame = [self handleScaleOverflow:newFrame];
newFrame = [self handleBorderOverflow:newFrame];
[UIView animateWithDuration:BOUNDCE_DURATION animations:^{
self.showImgView.frame = newFrame;
self.latestFrame = newFrame;
self.showImgView.contentMode=UIViewContentModeScaleAspectFit;
}];
}*/
/* if(pinchGestureRecognizer.scale > 1.0)
{*/
// big
CGRect newFrame = self.showImgView.frame;
newFrame = [self handleScaleOverflow:newFrame];
newFrame = [self handleBorderOverflow:newFrame];
[UIView animateWithDuration:BOUNDCE_DURATION animations:^{
self.showImgView.frame = newFrame;
self.latestFrame = newFrame;
}];
//}
}
}
可能会帮助你。
答案 2 :(得分:0)
在VPImageCropperViewController.m文件中进行更改
// pinch gesture handler
- (void) pinchView:(UIPinchGestureRecognizer *)pinchGestureRecognizer
{
UIView *view = self.showImgView;
if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan || pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) {
view.transform = CGAffineTransformScale(view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);
self.showImgView.contentMode=UIViewContentModeRedraw;
self.editedImage=self.showImgView.image;
}
else if (pinchGestureRecognizer.state == UIGestureRecognizerStateEnded) {
if(view.frame.size.width <= self.cropFrame.size.width && view.frame.size.height <= self.cropFrame.size.height)
{
// Zoom out
CGRect newFrame = self.showImgView.frame;
UIImage *img=[self imageWithImage:self.originalImage scaledToSize:self.cropFrame.size];
newFrame = [self handleScaleOverflow:CGRectMake(0, 0, img.size.width, img.size.height)];
newFrame = [self handleBorderOverflow:CGRectMake(0, 0, img.size.width, img.size.height)];
newFrame = [self handleScaleOverflow:newFrame];
newFrame = [self handleBorderOverflow:newFrame];
[UIView animateWithDuration:BOUNDCE_DURATION animations:^{
self.showImgView.frame = newFrame;
self.latestFrame = newFrame;
self.showImgView.contentMode=UIViewContentModeScaleAspectFit;
CGRect cropRect = AVMakeRectWithAspectRatioInsideRect(self.showImgView.image.size, self.showImgView.frame);
NSLog(@"frame %f %f ",cropRect.size.width,cropRect.size.height);
}];
}
else
{
// Zoom In
CGRect newFrame = self.showImgView.frame;
newFrame = [self handleScaleOverflow:newFrame];
newFrame = [self handleBorderOverflow:newFrame];
[UIView animateWithDuration:BOUNDCE_DURATION animations:^{
self.showImgView.frame = newFrame;
self.latestFrame = newFrame;
}];
}
}
}