-4

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

4

1 回答 1

2

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

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

而且,如果您想在滚动视图上设置图像,同时使用 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];
}
于 2012-11-23T05:05:15.623 回答