Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
缩放IOS中用于调整大小和裁剪图像的uiscrollview时出现问题_Ios_Objective C_Uiscrollview_Uiimageview_Pinchzoom - Fatal编程技术网

缩放IOS中用于调整大小和裁剪图像的uiscrollview时出现问题

缩放IOS中用于调整大小和裁剪图像的uiscrollview时出现问题,ios,objective-c,uiscrollview,uiimageview,pinchzoom,Ios,Objective C,Uiscrollview,Uiimageview,Pinchzoom,我正在开发一个应用程序,其中一个视图中有(图像保存),我有三种不同的尺寸,我希望在用户缩放从滚动视图中捕获的图像(当用户单击保存时)后,将图像保存在其中 以下是我的密码: 选择样式后,根据选择的类型设置宽度和高度,然后调用scrollview创建方法 -(void)viewDidAppear:(BOOL)animated{ if(!([getColor length] == 0)) { [theColored setHidden:NO]; [imageView setImage:

我正在开发一个应用程序,其中一个视图中有(图像保存),我有三种不同的尺寸,我希望在用户缩放从滚动视图中捕获的图像(当用户单击保存时)后,将图像保存在其中

以下是我的密码:

选择样式后,根据选择的类型设置宽度和高度,然后调用scrollview创建方法

-(void)viewDidAppear:(BOOL)animated{
if(!([getColor length] == 0))
{
    [theColored setHidden:NO];
    [imageView setImage:image];
    [theStyle setHidden:NO];
    [theStyled setHidden:YES];

}
if(!([getStyle length] == 0))
{
    [theColored setHidden:NO];
    [imageView setImage:image];
    [theStyle setHidden:YES];
    [theStyled setHidden:NO];
    [Save setHidden:NO];


    if([theType  isEqual: @"Pant"]){
        theW = 200;
        theH = 260;
    }else if ([theType isEqual:@"Shirt"])
    {
        theW = 220;
        theH = 220;
    }else if([theType isEqual:@"Shoes"])
    {
        theW = 200;
        theH = 60;
    }
   // UIImage *savedImage = image;

    CGFloat theScale = 1.0;
    [self setTheView:image andFrameW:&theW andFrameH:&theH andTheScale:&theScale];

      }}
方法如下:

-(void)setTheView:(UIImage *)savedImage andFrameW:(CGFloat *)theFW andFrameH:(CGFloat *)theFH andTheScale:(CGFloat *)theScale{
    NSLog(@"called");
    CGFloat theS = *theScale;
    CGFloat imgW ;
    CGFloat imgH;
    imgW = *theFW * theS;
    imgH = *theFH * theS;




    // = savedImage.size.height * theS;
    [dot removeFromSuperview];
    [scrollView setPagingEnabled:NO];
    [scrollView setShowsHorizontalScrollIndicator:NO];
    [scrollView setShowsVerticalScrollIndicator:NO];
    scrollView.layer.masksToBounds=YES;
    scrollView.minimumZoomScale = 0.1f;
    scrollView.maximumZoomScale = 5.0f;
  [scrollView setZoomScale:0.5];
    scrollView.layer.borderColor = [UIColor blackColor].CGColor;
    scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    [scrollView setContentSize:CGSizeMake(imgW*2,imgH*2)];

    dot =[[UIImageView alloc] initWithFrame:CGRectMake(imgW/2,imgH/2,imgW,imgH)];
    dot.image=savedImage;
    dot.contentMode = UIViewContentModeScaleAspectFit;


    [scrollView setScrollEnabled:YES];
    [scrollView setTranslatesAutoresizingMaskIntoConstraints:YES];
    scrollView.frame = CGRectMake(scrollView.frame.origin.x,scrollView.frame.origin.y, *theFW , *theFH);
    [scrollView setHidden:NO];
    [scrollView setContentOffset:CGPointMake(imgW/2,imgH/2) animated:NO];
    [scrollView addSubview:dot];


}
缩放方法:

- (UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return dot;
}

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale{
    NSLog(@"zoomed");
    NSLog(@"%f",scale);
   [self setTheView:image andFrameW:&theW andFrameH:&theH andTheScale:&scale];

}
问题: 我这里有两个问题:

1-缩放比例不是从最后到达的点开始

2-轻触缩放时,即使在开始缩放之前也会移动

更新编辑

两个问题都解决了

我没有在缩放后再次调用该方法,而是更改了内容大小

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale{

[self setTheView:image andFrameW:&theW andFrameH:&theH andTheScale:&scale];

}
替换为

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale{

scrollView.contentSize = CGSizeMake((dot.bounds.size.width*scale)*2,(dot.bounds.size.height*scale)*2);

}
但我有一个新的问题出现了,放大后contentOffSet上下不相等,还左下写

数字解释:

<----------------------------Content Size---------------------------->
|    left offset    |<---------Scrollviewframe--------->|Right offset|

但是什么也没做。

问题解决了,如果有人想在
allowsdediting=YES时使用scrollview进行裁剪和缩放,我想与大家分享答案不提供设置rect大小的功能

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale{

CGFloat zoomedW = dot.bounds.size.width*scale;
CGFloat zoomedH = dot.bounds.size.height*scale;
CGFloat frameW = scrollView.frame.size.width;
CGFloat frameH = scrollView.frame.size.height;

scrollView.contentSize = CGSizeMake(frameW+zoomedW ,frameH+zoomedH);

}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale{

CGFloat zoomedW = dot.bounds.size.width*scale;
CGFloat zoomedH = dot.bounds.size.height*scale;
CGFloat frameW = scrollView.frame.size.width;
CGFloat frameH = scrollView.frame.size.height;

scrollView.contentSize = CGSizeMake(frameW+zoomedW ,frameH+zoomedH);

}