繁体   English   中英

无法在滚动视图中看到图像

[英]Not able to see images inside scrollview

我有 2 个scrollviews和 1 个imageview scrollviews

现在在主scrollview我有另一个scrollview ,在这个scrollview我有图像。

所以,我的主ScrollView Scrollview名为“ ScrollView ”,子ScrollView scrollview名为“ scrView

现在我可以在“ ScrollView ”中添加“ scrView ”,但在“ scrViewscrView不到我的图像

我的编码如下:

int numberOfPages = 10;
    [scrollView setPagingEnabled:YES];
    [scrollView setContentSize:CGSizeMake(scrollView.bounds.size.width * numberOfPages, scrollView.bounds.size.height)];

    CGRect pageFrame;
    CGRect imageFrame;
    UIImageView *imageView;

    for(int i=0; i < numberOfPages; i++)
    {
        pageFrame = CGRectMake(i * scrollView.bounds.size.width+50, 0.0f, scrollView.bounds.size.width-100, scrollView.bounds.size.height);
        UIScrollView *scrView = [[UIScrollView alloc] init];
        imageFrame = CGRectMake(i * scrView.bounds.size.width, 0.0f, scrView.bounds.size.width, scrView.bounds.size.height);
        imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image1.jpg"]];
                    [scrView setFrame:pageFrame];
        [imageView setFrame:imageFrame];
        [scrView setBackgroundColor:[UIColor redColor]];

        [scrollView addSubview:scrView];
        [scrView addSubview:imageView];

        [imageView release];
    }

如果你看一下我的代码添加imageView一个subViewscrView ,但我不能看到模拟器图像。

问题是什么?

与我分享你的想法。

谢谢...

这是工作试试这个代码。 问题出在您的图像视图框架上

int numberOfPages = 10;
[scrollView setPagingEnabled:YES];
[scrollView setContentSize:CGSizeMake(scrollView.bounds.size.width * numberOfPages, scrollView.bounds.size.height)];

CGRect pageFrame;
CGRect imageFrame;
UIImageView *imageView;

for(int i=0; i < numberOfPages; i++)
{
    pageFrame = CGRectMake(i * scrollView.bounds.size.width+50, 0.0f, scrollView.bounds.size.width-100, scrollView.bounds.size.height);
    UIScrollView *scrView = [[UIScrollView alloc] initWithFrame:pageFrame];
    imageFrame = CGRectMake(0.0, 0.0f, scrView.bounds.size.width, scrView.bounds.size.height);

    imageView = [[UIImageView alloc] initWithFrame:imageFrame];
    imageView.image=[UIImage imageNamed:@"image1.jpg"];

   // [scrView setFrame:pageFrame];

    [scrView setBackgroundColor:[UIColor redColor]];
    [scrView addSubview:imageView];
    [scrollView addSubview:scrView];


    [imageView release];
}

设置背景颜色为您的ImageView太..然后登录并检查scrView&IMAGEFRAME 还可以使用bringSubviewToFront:属性。

for(int i=0; i < numberOfPages; i++)
    {
        UIScrollView *scrView = [[UIScrollView alloc] init];
        [scrView setBackgroundColor:[UIColor redColor]]; 
        pageFrame = CGRectMake(i * scrollView.bounds.size.width+50, 0.0f, scrollView.bounds.size.width-100, scrollView.bounds.size.height);

        imageFrame = CGRectMake(i * scrView.bounds.size.width, 0.0f, scrView.bounds.size.width, scrView.bounds.size.height);
        imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image1.jpg"]];
                    [scrView setFrame:pageFrame];
        [imageView setFrame:imageFrame];
        [imageView setBackgroundColor:[UIColor blueColor]]
        [scrView addSubview:imageView];
        [scrView bringSubviewToFront:imageView];
        [imageView release];

        [scrollView addSubview:scrView];
        [scrollView bringSubviewToFront:scrView];
    }

只需尝试从您的代码伙伴设置这样..

[scrView setBackgroundColor:[UIColor clearColor]];
[scrView addSubview:imageView]; /// first add imageview and then scrview (screen view) to scrollview
[scrollView addSubview:scrView];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM