2012-06-08 67 views
0

我使用ktphotobrowser作为我的应用程序。在大图像屏幕(ktphotoscrollviewcontroller)当我缩放图像两次点击时,scrollview(ktphotoview - 它是一个uiscrollview对象)的内容大小增长到bound.size * maximumzoomscale,但我缩放后的图像大小仍然小于scrollview的内容大小。缩放的图像大小和scrollview的contentize都必须相同,所以我可以在代码中进行这些计算?ios ktphotobrowser将scrollview的内容大小设置为zommed图像大小

如果有人使用ktphotobrowser可以帮助我解决这个问题,我将非常感激。

我发现水龙头计数,但此代码后,我无法找到哪里是contentsize增长(变焦)或图像增长(变焦)代码

下面你可以找到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; 
} 
+0

你好。我有同样的问题。你弄明白了吗?如果我这样做,我会告诉你。 – ratsimihah

回答

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)]; 





    } 
} 
} 
相关问题