UIImageView与大图像。问题 [英] UIImageView with big image. issue

查看:115
本文介绍了UIImageView与大图像。问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现iPhone Photo App(默认的iPhone应用程序)。当我想加载大图像(2500 * 3700)时,我遇到了困难。当我想从一个图像滚动到另一个图像时,我看到一些像口吃的东西。要显示图像我使用Apple网站上的ImageScrollView它有显示方法:ImageScrollView.m

I want to implement iPhone Photo App (default iPhone app). I faced difficulties, when I want to load big image (2500 * 3700). When I want to scroll from one image to another, I see something like stuttering. To display images I use ImageScrollView from apple site It has displaying method: ImageScrollView.m

- (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图像。然后在后台我加载3600 * 3600图像

For my app I have 600*600 images, I show them first. When user scrolls to next image he sees only 600*600 image. Then in background I load 3600 * 3600 image

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

我知道,当图像的尺寸为3600 * 3600并且我想在640中显示图像时* 960屏幕,iPhone浪费1秒的主要排队时间来缩放图像,这就是为什么我在这1秒内无法滚动到下一张图像。

I see, that when the dimensions of image are 3600 * 3600 and I want to display image in 640 * 960 screen, iPhone waste 1 second of main queue time to scale the image, and that's why I can't scroll to next image during this 1 second.

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

I want to scale image, because I need user to be able to zoom this image. I tried to use this approach, but this didn't help.

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

I see some possible solutions:

1)在后台提供UIImageView中的图像缩放(但我知道,UI应仅在主线程中更改)

1) to provide scaling of image in UIImageView in background (but I know, that UI should be changed only in main thread)

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

2) to use - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollViewCalled to show only 600 * 600 image at the beginning and then load big image, when user tries to zoom (but I tried this, and I will loose 1 second, when I try to init UIImageView with bigImage and then return this UIImageView; And I can't even implement it, because I see bad scroll view, where scrolling behavior is wrong (difficault to explain), when I try to return different view for different scales)

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


推荐答案

不幸的是,该图像太大,iPhone无法处理。我知道在iPad上,限制大致是设备屏幕的大小。任何大于那个,你将不得不使用CATiledLayer。

Unfortunately, that image is too large for the iPhone to handle. I know on the iPad, the limit is roughly the size of the device screen. Any bigger than that and you'll have to use a CATiledLayer.

我会看一下过去三年的WWDC UIScrollView演示文稿,从2010年开始。在那里,他们讨论了在iPhone上处理大图像的方法。示例代码也可以帮助您。

I would take a look at the WWDC UIScrollView presentations over the last three year, starting with 2010. In that, they discuss ways to handle large images on the iPhone. The sample code will also get you on your way.

祝你好运!

这篇关于UIImageView与大图像。问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆