1

我有 2scrollviews和 1 imageview

现在在 Main 里面scrollview我有另一个scrollview,在这个里面scrollview我有图像。

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

现在我可以在scrView里面添加“ ScrollView”但是我看不到里面的图片“ scrView

我的编码如下:

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

如果您查看我添加的代码imageViewsubViewscrView我无法在模拟器中看到图像。

问题是什么?

和我分享你的想法。

谢谢...

4

3 回答 3

2

这是工作尝试这段代码。问题出在您的 imageview 框架上

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];
}
于 2012-11-28T05:41:19.453 回答
0

也为您的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];
    }
于 2012-11-28T05:22:26.147 回答
0

试着从你的代码伙伴那里设置这样的..

[scrView setBackgroundColor:[UIColor clearColor]];
[scrView addSubview:imageView]; /// first add imageview and then scrview (screen view) to scrollview
[scrollView addSubview:scrView];
于 2012-11-28T05:31:34.677 回答