2012-11-28 9 views
6

私はUIScrollView内にいくつかの画像を表示する必要があるiPhoneアプリケーションを作成しています。前の画像。また、下部にはボタンが1つあります。ユーザーがそのボタンをクリックすると、スクロールビューで選択した画像が表示されます。私はスクロールビュー内に複数の画像を表示する方法を知りたいのですが、どの画像がスクロールビュー内にあるかを確認します。iOSのUIScrollView内に複数の画像を表示するには

+0

あなたがこれまで何をしています –

+0

ダイレクトコードを手に入れたようですか?それをやったことがありますか? –

答えて

5

例を理解してほしい - nbetweenは、あなたがイメージあなただけのシンプルなindexstart ++またはを見せる左右ボタン.COMあなたのイメージ名の場合

は数字だけではありません。

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

    [scrollView setPagingEnabled:YES]; 
    [scrollView setAlwaysBounceVertical:NO]; 

    NSArray *imagesArray = [NSArray arrayWithObjects:@"img1.png", @"img2.png", @"img3.png", nil]; 

    for (int i = 0; i < [imagesArray count]; i++) 
    { 
     CGFloat xOrigin = i * scrollView.frame.size.width; 

     UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0, scrollView.frame.size.width, scrollView.frame.size.height)]; 
     [imageView setImage:[UIImage imageNamed:[imagesArray objectAtIndex:i]]]; 
     [imageView setContentMode:UIViewContentModeScaleAspectFit]; 

     [scrollView addSubview:imageView]; 
    } 

    [scrollView setContentSize:CGSizeMake(scrollView.frame.size.width * [imagesArray count], scrollView.frame.size.height)]; 
+0

私はこれを行い、ポートレートモードで正常に動作します。私は別のイメージ配列を持っている場合、私はランドスケープモードのためにそれを行う方法? plzはこれについていくつかの提案をします。 – Mak13

+0

画面が横向きに回転したときに検出する必要があります。検出されたら、イメージ配列内のイメージ名を変更して、古いスクロールビューを削除し、新しいイメージ配列で新しいものを描画します。 – tnylee

+0

私は同じ昨日だけでした。とにかく返事をありがとう。 – Mak13

2

Apple.developerPhotoScrollerは個別にパンとズームすることができます写真を表示し、ページ付けのためのリッチなユーザー体験を作成するための組み込みUIScrollViewsとCATiledLayerの使用方法を示します。

CATiledLayerは、高解像度画像や大きな写真セットでページング、パン、ズームのパフォーマンスを向上させるために使用されます。

0

あなた単に最初 ランタイムと画像上に新しいビューを作成し、タグ値でタグ1000または100およびインクリメントなどのすべてのビューを割り当て、その後に、このビューを追加scrollview左右移動用の2つのボタンとその出口アクションを作り、あなたは、あなたがこれを使用し、左右ボタンでこれを行うためにループを使用して、この

 indexStart=100; 
UIView *AddView=[[UIView alloc]initWithFrame:CGRectMake(55, 0, 100, 100)]; 

       AddView.tag=indexStart; 
       btnTap.tag=indexStart; 

       UIImageView *imgview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)]; 



       [AddView addSubview:imgview]; 

       imgview.image=image; 
       imgview.tag=1000; 
       [ScrollView addSubview:AddView]; 
       [imgArray addObject:AddView]; 

のように可変配列にして、すべてのscrollviewサブビューを追加このコードではeditImgeViewは画像ビューiですユーザーは右または左のボタンを選択した場合

for (int index = 0; index < [imgAddArrayAfter count]; index ++) { 
     NSLog(@"index %d",index); 
     UIView *vc=[imgArray objectAtIndex:index]; 
     NSLog(@"view tag %d",vc.tag); 
     if(vc.tag == indexStart) 
     { 

      UIImageView *modalView=(UIImageView *) [vc viewWithTag:1000]; 
      editImgeView.image=modalView.image; 
     } 
    } 

私はあなたがdanielbeard.wordpressから;-)

0
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
    scrollView.contentSize = CGSizeMake(320, 465); 

    [scrollView setScrollEnabled:YES]; 
    [scrollView setPagingEnabled:YES]; 
    [scrollView setAlwaysBounceVertical:NO]; 
    [self.view addSubview:scrollView]; 

    NSMutableArray *arrImage = [NSMutableArray arrayWithObjects:@"food1.jpeg", @"food2.jpeg", @"food3.jpeg",@"food4.jpeg", @"food5.jpeg", @"food6.jpeg",@"food7.jpeg", @"food8.jpeg", @"foo9.jpeg",@"food10.jpeg", @"food11.jpeg", @"food12.jpeg",@"food13.jpeg", @"food14.jpeg", @"food15.jpeg", @"food16.jpeg", nil]; 

    for (int i = 0; i < [arrImage count]; i++) 
    { 
     CGFloat xOrigin = i * scrollView.frame.size.width; 

     UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0, scrollView.frame.size.width, scrollView.frame.size.height)]; 
     [imageView setImage:[UIImage imageNamed:[arrImage objectAtIndex:i]]]; 
     [imageView setContentMode:UIViewContentModeScaleAspectFit]; 

     [scrollView addSubview:imageView]; 
    } 

    [scrollView setContentSize:CGSizeMake(scrollView.frame.size.width * [arrImage count], scrollView.frame.size.height)]; 
} 
関連する問題