UINavigationController:推送大图像时转换不顺畅

时间:2011-10-09 11:24:57

标签: iphone ios4 uinavigationcontroller uiimageview uiimage

我是iPhone开发的初学者,在我的应用程序中遇到UINavigationControoler问题。

我有一个UITableView中主应用程序包的图像列表(带有缩略图),当选择图像时,UIScrollView视图被推送到导航控制器。当我使用大图像(例如用iPhone相机拍摄的图像)时,在推送过渡动画期间会出现问题。它不流畅(低帧率)所以我想知道问题是什么(+弹出过渡没有问题)。这是我在图片视图中的代码段:

- (void)loadView 
{
    //consider loading in seperate thread?
    //[NSThread detachNewThreadSelector:@selector(loadImage:) toTarget:self withObject:[photo URL]];

    UIImage *image = [UIImage imageNamed :[photo URL]];
    imageView = [[UIImageView alloc] initWithImage:image];

    UINavigationController *navController = [self navigationController];

    //get navigation controller view frame
    CGRect scrollViewSize = self.navigationController.view.frame;

    //take navigation bar height into account for scroll view size
    if(![navController isNavigationBarHidden]) {
        scrollViewSize.size.height -= [[navController navigationBar] frame].size.height;
    } 

    //take status bar height into account for scroll view size}
    UIApplication *sharedApp = [UIApplication sharedApplication];
    if(![sharedApp isStatusBarHidden]) {
        scrollViewSize.size.height -= [sharedApp statusBarFrame].size.height;
    }

    //calculate minimum zoom scale
    CGSize screenSize = scrollViewSize.size;
    CGFloat widthRatio = screenSize.width / image.size.width;
    CGFloat heightRatio = screenSize.height / image.size.height;
    CGFloat initialZoom = (widthRatio > heightRatio) ? heightRatio : widthRatio;

    //init scroll view
    scrollView = [[PhotoScrollView alloc] initWithFrame:scrollViewSize];
    [scrollView setMaximumZoomScale:1.0];
    [scrollView setMinimumZoomScale:initialZoom];
    [scrollView setBouncesZoom:YES];
    [scrollView setContentSize :[image size]];
    [scrollView setScrollEnabled :YES];
    [scrollView setDelegate: self];

    //imageView has to be added to scrollView in order for setZoomScale to work
    [scrollView addSubview :imageView];

    [scrollView setZoomScale:initialZoom];

    imageDescription = [[UILabel alloc] initWithFrame:CGRectMake(0, (screenSize.height/2)-20, screenSize.width, 40)];
    [imageDescription setText:[[self photo] getDetails]];
    [imageDescription setFont:[UIFont systemFontOfSize:20]];
    [imageDescription setTextAlignment:UITextAlignmentCenter];
    [imageDescription setBackgroundColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.5]];
    [imageDescription setAlpha:0];

    [image release];
    [super loadView];
}

- (void)viewDidLoad
{
    [self.view addSubview :scrollView];
    [self.view addSubview:imageDescription];
    [super viewDidLoad];
}

我已经尝试在单独的线程中加载图像([NSThread detachNewThreadSelector:@selector(loadImage :) toTarget:self withObject:[photo URL]])但它没有帮助。我需要调整图像大小吗?另外我想知道如何编写默认的iPhone应用程序照片,因为它具有类似的功能,但在转换过程中图像模糊。

1 个答案:

答案 0 :(得分:1)

请注意,使用相机拍摄的图像会占用大量内存。在iPhone上拍摄Photos.app。他们从未真正向您展示原始照片。它们采用了许多尺寸的图像,并且根据比例因子(即放大的方式),它们会引入更高分辨率的照片。但是直接缩放仍然无法使您获得与原始图像相同的分辨率,原因如下:性能。

我强烈建议您观看this WWDC 2010 video这个概念并大大提高应用程序的性能。