如何在UIScrollView中加载许多图像

时间:2012-11-23 04:50:48

标签: iphone ios uiscrollview uiimageview

我在uiscrollview中使用了很多图像我想在开始时加载前3或4个图像,然后我想加载并在滚动时释放其他图像给出一些例子。

1 个答案:

答案 0 :(得分:2)

看到这个有很多种类的最佳CoverFlow .....

  1. iCarousel //只需根据您的要求更改类型,在此示例中,您将获得带动画的每种类型的图像显示/输出
  2. openflow
  3. 如果你想在scrollview上使用imagePath中的两个oriantation设置图像,那么这是我创建使用它的简单方法..只需更改一些你想要的代码..

    -(void) imageFromImagePath : (NSString *) path {
    
        UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
        imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:path]];
        UIImage *img = [UIImage imageWithContentsOfFile:path];
    
        if (img != nil) {
            [imageView setBackgroundColor:[UIColor clearColor]];
            fullFrame = imageView.frame;
    
            float expWidth, expHeight, orgWidth, orgHeight;
    
            orgWidth = imageView.frame.size.width;
            orgHeight = imageView.frame.size.height;
    
            if (orgWidth < orgHeight) {
    
                if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) {
                    expWidth = 480;
                    expHeight = (orgHeight * expWidth)/orgWidth;
    
                    if (expHeight < 300) {
                        expHeight = 300;
                        expWidth = (orgWidth * expHeight)/orgHeight;
                    }           
                }
                else {
    
                    expWidth = 320;
                    expHeight = (orgHeight * expWidth)/orgWidth;
    
                    if (expHeight < 460) {
                        expHeight = 460;
                        expWidth = (orgWidth * expHeight)/orgHeight;
                    }
                }   
            }
            else {      
    
                if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) {
                    expHeight = 300;
                    expWidth = (orgWidth * expHeight)/orgHeight;
    
                    if (expWidth < 480) {
                        expWidth = 480;
                        expHeight = (orgHeight * expWidth)/orgWidth;
                    }           
                }
                else {          
                    expHeight = 460;
                    expWidth = (orgWidth * expHeight)/orgHeight;
    
                    if (expWidth < 320) {
                        expWidth = 320;
                        expHeight = (orgHeight * expWidth)/orgWidth;
                    }
                }       
            }
    
            imageView.contentMode = UIViewContentModeScaleToFill;   
            imageView.image = img;
            [scroller addSubview:imageView];
            [imageView release];
            [scroller bringSubviewToFront:scrollingWheel];
            //[self addSubview:scroller];
    
            [imageView setNeedsLayout];
            [imageView setNeedsDisplay];
    
            imgWidth = expWidth;
            imgHeight = expHeight;
            [scrollingWheel stopAnimating];
    
            imageView.frame = CGRectMake(0,0,expWidth,expHeight);
    
            //scroller.frame = CGRectMake(0,0,expWidth,expHeight);
            scroller.contentSize = CGSizeMake(expWidth, expHeight); 
        }
        else {
    
        }
    
        //[self performSelector:@selector(hideScrollingWheel) withObject:nil afterDelay:1.0];
    }