2012-03-23 3 views
0

私は複数の画像を持つスクロールビューを持っています。画像はスクロール可能です。UIScrollViewで画像を変更するには

scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 

scrollView.pagingEnabled = YES; 

scrollView.delegate = self; 

scrollView.showsVerticalScrollIndicator = NO; 

scrollView.showsHorizontalScrollIndicator = NO; 


NSInteger numberOfViews = [arrayImage count]; 

for (int i = 0; i < numberOfViews; i++) 
{ 
    CGFloat yOrigin = i * scrollView.frame.size.width; 
    imageView = [[UIImageView alloc]initWithFrame:CGRectMake(yOrigin +30, 0, self.view.frame.size.width-60 , self.view.frame.size.height)]; 
    imageView.image = [UIImage imageNamed:[arrayImage objectAtIndex:i]]; 
    [scrollView addSubview:imageView]; 
    [imageView release]; 
} 
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * numberOfViews,0); 
[self.view addSubview:scrollView]; 
[scrollView release] 

アプリケーションは、iPadの向きで動作しますが、画像が正しくランドスケープモードにスクロールされていません。

私は、次のコードを使用しています。

ポートレートモードでは問題なく動作しますが、画像は横長モードでマージされます。

誰かがどんな考えを持っている場合は、共有してください....

+0

スライダは、画像を含む下部に、私はUISliderから選択された画面上のそれぞれの画像を表示したい。最後のUIImageViewに画像が表示されますが、現在のUIImageViewに表示します。助けてください.. –

+0

uiscrollviewのautoresizeオプションが無効になっていることを確認してください。 – hchouhan02

+0

私は答えを投稿しました...これは、画像をスライドさせて画像ビューで画像を表示するのに便利です... – Krunal

答えて

0

あなたが設定する必要がありますインターフェイスの向きが変わるたびにその目的のための画像フレームを作成するか、向きを変更した後に画像を再描画する必要があります

+0

お返事ありがとうございます。 –

+0

問題を解決した場合はその答えを受け入れて、他の人が同じ問題を解決するのを助けることができます –

1

...

これを設定
scrollView.delegate = self; 
scrollView.scrollEnabled = YES; 

int scrollWidth = 120; 
scrollView.contentSize = CGSizeMake(scrollWidth,80);  


int xOffset = 0; 
imageView.image = [UIImage imageNamed:[imagesName objectAtIndex:0]]; 

for(int index=0; index < [imagesName count]; index++) 
{  
    UIImageView *img = [[UIImageView alloc] init]; 
    img.bounds = CGRectMake(10, 10, 50, 50); 
    img.frame = CGRectMake(5+xOffset, 0, 50, 50); 
    NSLog(@"image: %@",[imagesName objectAtIndex:index]); 
    img.image = [UIImage imageNamed:[imagesName objectAtIndex:index]]; 
    [images insertObject:img atIndex:index];   
    scrollView.contentSize = CGSizeMake(scrollWidth+xOffset,110); 
    [scrollView addSubview:[images objectAtIndex:index]]; 

    xOffset += 70; 
} 

を、このいずれかを試してみてください...

imagesName = [[NSArray alloc]initWithObjects:@"image1.jpg",@"image2.jpg",@"image3.jpg",@"image4.jpg",@"image5.jpg",@"image6.png",@"image7.png",@"image9.png",nil]; 
images = [[NSMutableArray alloc]init]; 
+0

私の要求に従って正しく動作しませんでした。 –

+0

私はあなたがスクロールビューにある画像をスライドして、どれが選択されているかを表示したいと思いますか?? – Krunal

+0

はい、私は同じことが欲しいです。 –

関連する問題