0

双击图像视图后,我想将图像大小设置为与滚动视图的内容大小相同。

我在我的应用程序和它的 ktphotoview 对象(它是一个 uiscrollview 对象)中使用 ktphotobrowser 我有以下双击代码

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
UITouch *touch = [touches anyObject];

if ([touch view] == self) {
  if ([touch tapCount] == 2) {
     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(toggleChromeDisplay) object:nil];
     //[self zoomToRect:[self zoomRectForScale:[self maximumZoomScale] withCenter:[touch locationInView:self]] animated:YES];

      //[self setContentSize:imageView_.bounds.size];
      //[self zoomToLocation:[touch locationInView:self]];

       CGPoint pointInView = [touch locationInView:self];

       // Get a zoom scale that's zoomed in slightly, capped at the maximum zoom scale specified by the scroll view
       CGFloat newZoomScale = self.zoomScale * 2.0;
       NSLog(@"zoomscale %f",newZoomScale);
       newZoomScale = MIN(newZoomScale, self.maximumZoomScale);

       // Figure out the rect we want to zoom to, then zoom to it
       CGSize scrollViewSize = self.bounds.size;

       CGFloat w = scrollViewSize.width / newZoomScale;
       CGFloat h = scrollViewSize.height / newZoomScale;
       CGFloat x = pointInView.x - (w / 2.0f);
       CGFloat y = pointInView.y - (h / 2.0f);

      CGRect rectToZoomTo = CGRectMake(x, y, w, h);

       [self zoomToRect:rectToZoomTo animated:YES];


  }
}
}

scrollview 的最大缩放比例设置为 2.0

当我双击 myimageview 时,我的图像的原始尺寸为 1280x853,绑定模具高度为 640,滚动视图的内容尺寸高度为 960(uiscreen.size.height * maximumzoomscale)

但我想要的是图像视图的高度和内容大小的高度应该相同,因此用户不能滚动到图像之外

我如何以及在哪里可以在此视图中进行这些计算和设置我可以在哪里设置它们的高度和宽度?

谢谢

4

1 回答 1

0

也许不是最好的解决方案,但我用下面的代码块解决了我的问题:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
UITouch *touch = [touches anyObject];

if ([touch view] == self) {
  if ([touch tapCount] == 2) {


     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(toggleChromeDisplay) object:nil];
      [self zoomToRect:[self zoomRectForScale:[self maximumZoomScale] withCenter:[touch locationInView:self]] animated:YES];
      float abc=(self.contentSize.height-(imageView_.image.size.height*320/imageView_.image.size.width*self.maximumZoomScale))/2 *-1;

      [self setContentInset:UIEdgeInsetsMake(abc, 0, abc, 0)];





  }
 }
}
于 2012-06-15T14:38:10.320 回答