2012-06-25 71 views
0

我想实现iPhone照片应用程序(默认iPhone应用程序)。当我想要加载大图像(2500 * 3700)时,我遇到了困难。当我想从一幅图像滚动到另一幅图像时,我看到了像口吃这样的东西。要显示从苹果的网站它的显示方法我用ImageScrollView图片:ImageScrollView.mUIImageView与大图像。问题

- (void)displayImage:(UIImage *)image 
{ 
    // clear the previous imageView 
    [imageView removeFromSuperview]; 
    [imageView release]; 
    imageView = nil; 

    // reset our zoomScale to 1.0 before doing any further calculations 
    self.zoomScale = 1.0; 
    self.imageView = [[[UIImageView alloc] initWithImage:image] autorelease]; 
    [self addSubview:imageView]; 

    self.contentSize = [image size]; 
    [self setMaxMinZoomScalesForCurrentBounds]; 
    self.zoomScale = self.minimumZoomScale; 
} 

- (void)setMaxMinZoomScalesForCurrentBounds 
{ 
    CGSize boundsSize = self.bounds.size; 
    CGSize imageSize = imageView.bounds.size; 

    // calculate min/max zoomscale 
    CGFloat xScale = boundsSize.width/imageSize.width; // the scale needed to perfectly fit the image width-wise 
    CGFloat yScale = boundsSize.height/imageSize.height; // the scale needed to perfectly fit the image height-wise 
    CGFloat minScale = MIN(xScale, yScale);     // use minimum of these to allow the image to become fully visible 

    // on high resolution screens we have double the pixel density, so we will be seeing every pixel if we limit the 
    // maximum zoom scale to 0.5. 
    CGFloat maxScale = 1.0/[[UIScreen mainScreen] scale]; 

    // don't let minScale exceed maxScale. (If the image is smaller than the screen, we don't want to force it to be zoomed.) 
    if (minScale > maxScale) { 
     minScale = maxScale; 
    } 

    self.maximumZoomScale = maxScale; 
    self.minimumZoomScale = minScale; 
} 

对于我的应用我有600张* 600的图片,我告诉他们第一。当用户滚动到下一个图像时,他只能看到600 * 600的图像。然后在后台I加载3600 * 3600图像

[operationQueue addOperationWithBlock:^{ 
    UIImage *image = [self getProperBIGImage]; 
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 
     ImageScrollView *scroll = [self getCurrentScroll]; 
     [scroll displayImage:newImage]; 
    }]; 
}]; 

我看到的,当图像的尺寸是3600 * 3600和我想显示在640×960的屏幕图像,iPhone浪费的主队列时间1秒至缩放图像,这就是为什么我在这1秒内无法滚动到下一张图像的原因。

我想缩放图像,因为我需要用户能够放大此图像。我试图使用这种方法,但这没有帮助。

我看到一些可能的解决方案:

1)在后台提供图像的缩放在UIImageView的(但我知道,那UI只能在主线程中进行更改)

2)使用 - ( UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollViewCalled在开始时只显示600 * 600图像,然后加载大图像,当用户尝试缩放时(但我尝试过这样,当我尝试初始化UIImageView与bigImage然后返回这个UIImageView;我甚至不能实现它,因为我看到坏滚动视图,滚动行为是错误的(difficault解释),当我尝试返回不同的比例不同的视图)

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollViewCalled 
{ 
    if (!zooming) 
    { 
     ImageScrollView *scroll = (ImageScrollView *)scrollViewCalled; 
     UIImageView *imageView = (UIImageView *)[scroll imageView]; 
     return imageView; 
    } 
    else 
    { 
     UIImageView *bigImageView = [self getBigImageView]; 
     return bigImageView; 
    } 
} 

回答

1

不幸的是,该图片太大,iPhone无法处理。我知道在iPad上,限制大概是设​​备屏幕的大小。任何比这更大的,你将不得不使用CATiledLayer。

从2010年开始,我将在过去三年中看看WWDC UIScrollView演示文稿。在这篇文章中,他们讨论了在iPhone上处理大型图像的方法。示例代码也将帮助您顺利完成任务。

祝你好运!