【问题标题】:How to load many images in UIScrollView [closed]如何在 UIScrollView 中加载许多图像 [关闭]
【发布时间】:2012-11-23 04:50:48
【问题描述】:

我在 uiscrollview 中使用了许多图像,我想在开始时加载前 3 或 4 张图像,然后我想在滚动时加载和释放其他图像。

【问题讨论】:

    标签: iphone ios uiscrollview uiimageview


    【解决方案1】:

    查看这个具有多种类型的最佳 CoverFlow .....

    1. iCarousel //只需根据您的要求更改类型,在此示例中,您将获得每种类型的带有动画的图像的显示/输出
    2. openflow

    如果你想在滚动视图上设置图像,同时使用 imagePath 的方向,那么这是我创建来使用它的简单方法.. 只需更改一些你想要的代码..

    -(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];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多