0

私は自分のアプリにktphotobrowserを使用しています。大きな画像画面(ktphotoscrollviewcontroller)で、2回タップして画像をズームすると、scrollview(ktphotoview-uiscrollviewオブジェクト)のコンテンツサイズがbound.size * maximumzoomscaleに拡大しますが、ズームした画像サイズはscrollviewのcontentsizeよりも小さくなります。ズームされた画像サイズとスクロールビューのコンテンツサイズの両方が同じである必要があるため、コードでこれらの計算をどこで実行できますか?

誰かがktphotobrowserを使用してこの問題について私を助けることができれば、私は非常に感謝します。

タップ数を見つけましたが、このコードの後、コンテンツサイズの拡大(ズーム)または画像の拡大(ズーム)コードがどこにあるかを見つけることができませんでした

以下に、タッピングカウントとズームアクションがコード化されているktphotoview.hページのコード全体を示します。

#import "KTPhotoView.h"
#import "KTPhotoScrollViewController.h"
#import <QuartzCore/QuartzCore.h>

@interface KTPhotoView (KTPrivateMethods)
- (void)loadSubviewsWithFrame:(CGRect)frame;
- (BOOL)isZoomed;
- (void)toggleChromeDisplay;
@end

@implementation KTPhotoView

@synthesize scroller = scroller_;
@synthesize index = index_;



- (id)initWithFrame:(CGRect)frame
{
   self = [super initWithFrame:frame];
   if (self) {
      [self setDelegate:self];
      [self setMaximumZoomScale:2.0];
      [self setShowsHorizontalScrollIndicator:NO];
      [self setShowsVerticalScrollIndicator:NO];
      [self loadSubviewsWithFrame:frame];

        NSLog(@"scrollview2 %f",self.contentSize.height);
   }
   return self;
}

- (void)loadSubviewsWithFrame:(CGRect)frame
{
   imageView_ = [[UIImageView alloc] initWithFrame:frame];
   [imageView_ setContentMode:UIViewContentModeScaleAspectFit];
   [self addSubview:imageView_];
}

- (void)setImage:(UIImage *)newImage 
{
   [imageView_ setImage:newImage];
}

- (void)layoutSubviews 
{
   [super layoutSubviews];

   if ([self isZoomed] == NO && CGRectEqualToRect([self bounds], [imageView_ frame]) == NO) {
      [imageView_ setFrame:[self bounds]];
   }
}

- (void)toggleChromeDisplay
{
   if (scroller_) {
      [scroller_ toggleChromeDisplay];
   }
}

- (BOOL)isZoomed
{
   return !([self zoomScale] == [self minimumZoomScale]);
}

- (CGRect)zoomRectForScale:(float)scale withCenter:(CGPoint)center 
{

   CGRect zoomRect;

   // the zoom rect is in the content view's coordinates. 
   //    At a zoom scale of 1.0, it would be the size of the imageScrollView's bounds.
   //    As the zoom scale decreases, so more content is visible, the size of the rect grows.
   zoomRect.size.height = [self frame].size.height / scale;
   zoomRect.size.width  = [self frame].size.width  / scale;

   // choose an origin so as to get the right center.
   zoomRect.origin.x    = center.x - (zoomRect.size.width  / 2.0);
   zoomRect.origin.y    = center.y - (zoomRect.size.height / 2.0);
    NSLog(@"zoomRectHeight %f",[self frame].size.height);
   return zoomRect;
}

- (void)zoomToLocation:(CGPoint)location
{
   float newScale;
   CGRect zoomRect;
   if ([self isZoomed]) {
      zoomRect = [self bounds];

   } else {
      newScale = [self maximumZoomScale];
      zoomRect = [self zoomRectForScale:newScale withCenter:location];

   }
  // NSLog(@"zoomRectHeight %f",location.);
   [self zoomToRect:zoomRect animated:YES];
}

- (void)turnOffZoom
{
   if ([self isZoomed]) {
      [self zoomToLocation:CGPointZero];
   }
}

- (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 zoomToLocation:[touch locationInView:self]];
      }
   }
}

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

   if ([touch view] == self) {
      if ([touch tapCount] == 1) {
         [self performSelector:@selector(toggleChromeDisplay) withObject:nil afterDelay:0.5];
      }
   }
}

#pragma mark -
#pragma mark UIScrollViewDelegate Methods

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
   UIView *viewToZoom = imageView_;
    NSLog(@"scrollview %f",self.contentSize.height);
   return viewToZoom;
}
4

1 に答える 1

0

私は私の問題を解決するためにktphotoview.mファイルで以下のコードを使用しますこれが役立つことを願っています:

- (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-08-12T22:36:04.107 に答える