1

我的问题是我CGRectUIScrollview使用zoomToRect. UIScrollview缩放时我正在设置contentOffset属性。

代码如下:

if(image != nil) {

        CGSize zoomViewSize = image.frame.size;


        CGSize scrollViewSize = self.bounds.size;

        if(zoomViewSize.width < scrollViewSize.width) {
            anOffset.x = -(scrollViewSize.width - zoomViewSize.width) / 2.0;
        }

        if(zoomViewSize.height < scrollViewSize.height) {
            anOffset.y = -(scrollViewSize.height - zoomViewSize.height) / 2.0;
        }
    }
super.contentOffset = anOffset;

缩放后,我正在设置内容插入属性,以便图像位于中心。对于内容插图,代码如下。

-(void)zoomtorect:(CGRect)rect animated:(BOOL)animated {

[super zoomtorect:rect animated:YES];


CGFloat pageWidth = image.image.size.height;



         CGSize imageSize = rect.size;
         CGSize zoomedImageSize = CGSizeMake(imageSize.width * 0.2, imageSize.height * 0.2);
         CGSize pageSize = self.bounds.size;

         //scLayer.frame = rect;
         UIEdgeInsets inset = UIEdgeInsetsZero;
         if (pageSize.width > zoomedImageSize.width) {
             inset.left = (pageSize.width - zoomedImageSize.width) / 2;
             inset.right = inset.left;
         }
         if (pageSize.height > zoomedImageSize.height) {
             inset.top = (pageSize.height - zoomedImageSize.height) / 2;
             inset.bottom = inset.top;
         }

         self.contentInset = inset;
}

此代码在屏幕之间切换我的图像视图。在这里一切正常。我的问题是我必须只显示imageView其余部分的缩放部分是黑色的。为了计算缩放区域,我正在进行以下计算。

CGSize imageSize = rect.size;
    CGSize zoomedImageSize = CGSizeMake(imageSize.width * scroll.maximumZoomScale, imageSize.height *scroll.maximumZoomScale);
    CGSize pageSize = scroll.bounds.size;

    UIEdgeInsets inset = UIEdgeInsetsZero;
    if (pageSize.width > zoomedImageSize.width) {
        inset.left = (pageSize.width - zoomedImageSize.width) / 2;
        inset.right = inset.left;
    }
    if (pageSize.height > zoomedImageSize.height) {
        inset.top = (pageSize.height - zoomedImageSize.height) / 2;
        inset.bottom = inset.top;
    }

    CGRect zoomRect = [scroll convertRect:rect fromView:image];

    CGRect zoomRect1 = CGRectMake(inset.left, inset.top+50, zoomRect.size.width, zoomRect.size.height);

zoomRect1是图像的缩放区域,这个值与我在屏幕上看到的不完全相同。在我做计算错误的地方请帮帮我。但我没有得到缩放图像区域的确切值。

提前致谢

4

1 回答 1

1

使用这个..完美工作

- (void)handleDoubleTap:(UIGestureRecognizer *)recognizer
{
    if(isAlreadyZoomed)
    {
        CGPoint Pointview = [recognizer locationInView:recognizer.view];
        CGFloat newZoomscal = 3.0;
        CGSize scrollViewSize = self.scrollContainer.bounds.size;
        CGFloat width = scrollViewSize.width/newZoomscal;
        CGFloat height = scrollViewSize.height /newZoomscal;
        CGFloat xPos = Pointview.x-(width/2.0);
        CGFloat yPos = Pointview.y-(height/2.0);
        CGRect rectTozoom=CGRectMake(xPos, yPos, width, height);
        [self.scrollContainer zoomToRect:rectTozoom animated:YES];
        [self.scrollContainer setZoomScale:3.0 animated:YES];
        isAlreadyZoomed = NO;
    }
    else
    {
        [self.scrollContainer setZoomScale:1.0 animated:YES];
        isAlreadyZoomed = YES;
    }
}

isAlreadyZoomed是一个BOOL

于 2013-03-22T09:27:30.237 回答