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 の maximumzoomscale は 2.0 に設定されています

私の画像の元のサイズは 1280x853 です。ダブルタップすると、myimageview のバインドされたダイの高さは 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 に答える