1

私は 2scrollviewsと 1を持っていimageviewます。

今、メインのscrollview中に別のものがあります。scrollviewこれscrollviewにはイメージがあります。

つまり、「 」という名前のメインScrollviewと「」という名前ScrollViewのサブscrollviewscrView

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

imageViewとして追加したコードを見るとsubViewscrViewシミュレーターで画像を見ることができません。

何が問題ですか?

あなたのアイデアを私と共有してください。

ありがとう...

4

3 に答える 3

2

これは機能しています。このコードを試してください。イメージビュー フレームに問題がありました

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

コードメイトからこのように設定してみてください..

[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 に答える
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 に答える