2012-03-12 9 views
0

カルーセルビューですべての画像をスクロールしたいと思います。しかし、私の見解では、アニメーションは、私が中間の画像をスクロールすると動き始めます。私はそれの隣の他の画像に触れると、彼らは移動しません。私は、viewForItemAtIndexメソッドでボタンを使用します。見えるすべての画像をどのように動かすことができますか?icarouselですべての画像をスクロールする方法

これは私のviewForItemAtIndexMethodです:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(ReflectionView *)view 
{ 


UIButton* button = nil; 
if (view == nil) 
{ 
    UIImage *image = [arrKitapKapaklari objectAtIndex:index]; 
    view = [[[ReflectionView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, image.size.width, image.size.height)] autorelease]; 

    //no button available to recycle, so create new one 
    [view setBackgroundColor:[UIColor clearColor]]; 

    button = [UIButton buttonWithType:UIButtonTypeCustom]; 
    button.frame = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height); 
    [button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal]; 
    [button setBackgroundImage:image forState:UIControlStateNormal]; 
    button.titleLabel.font = [button.titleLabel.font fontWithSize:50]; 
    [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; 
    button.tag = 99; 
    [view update]; 
    [view addSubview:button]; 

} 
else 
{ 
    button = (UIButton *)[view viewWithTag:99]; 
} 


[button setTitle:[NSString stringWithFormat:@"%i", index] forState:UIControlStateNormal]; 

return view; 
} 
+0

あなたのiCarouselフレームは何ですか? IBまたはコードで初期化していますか? –

+0

コードで初期化されました。しかし、私はそれがicarouselの代表的な方法であると思います。私は解決しようとするが、私は初心者です。私はすべての方法を理解していません –

+0

私はiCarouselがパンジェスチャ認識機能を持っていることを覚えています。カルーセルを設定する場所にコードフラグメントを投稿できますか? –

答えて

0

あなたのiCarouselフレームに問題があると思われます。おそらく、フレームの外にある他の要素に触れると、iCarouselジェスチャ認識ツールが接触しません。他の可能性は、あなたのビューの他のいくつかの要素が触れて、それをiCarouselに渡さないことです。 iCarouselは、主要な要素だけでなく、すべてのタッチを処理するように設計されています。あなたの投稿の下のコメントに書いたように、あなたのカルーセルの設定はすべて大丈夫ですか?

+0

はいあなたは書き込みます。どうもありがとう.. –

-1

これはあなたが(今私は、各画像の下にラベル/ wの画像を使用しています、画像が配列に格納されている)を扱っている方法のための私のコードです。

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view 
    { 

     if (index < [items count]) { 
      image = [UIImage imageNamed:[self.hldImage objectAtIndex:index]]; 
      view = [[UIImageView alloc] initWithImage:image]; 


      UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, image.size.height,image.size.width, 50)]; 
      NSString *carName = [NSString stringWithFormat:[hldName objectAtIndex:index]]; 
      label.backgroundColor = [UIColor clearColor]; 
      label.text = carName; 
      label.textColor = [UIColor whiteColor]; 
      label.textAlignment = UITextAlignmentCenter; 
      label.lineBreakMode = UILineBreakModeWordWrap; 
      label.numberOfLines = 99; 
      [view addSubview:label]; 
      [view setTag:index+1]; 

     } 
     return view; 
    } 

これはカルーセルで、私は中央にイメージを持って来るために実装したコード(これはICarousel.mである)

- (void)didTap:(UITapGestureRecognizer *)tapGesture 
{ 
    NSInteger index = [self indexOfItemView:[tapGesture.view.subviews lastObject]]; 
    if (centerItemWhenSelected && index != self.currentItemIndex) 
    { 
     NSLog(@"tapped item not at center, index = %i",index); 
     [self scrollToItemAtIndex:index animated:YES]; 
     NSUInteger tag = index; 
    } 
    if ([delegate respondsToSelector:@selector(carousel:didSelectItemAtIndex:)]) 
    { 
     [delegate carousel:self didSelectItemAtIndex:index]; 
     NSUInteger tag = index; 
    } 
    if (self.currentItemIndex) 
    { 
     NSLog(@"Current index item, index = %i",index); 
    } 
} 

すべての私のイメージでは、それらに関連付けられたタグを持っています。

+0

これは私が欲しいものではありません。カルーセルビューでは、4つの画像が表示されます。アニメーションを開始するには、私は中心のアイテムをスクロールする必要があります私は他の画像をスクロールしようとすると動作しません。アニメーションが動き出しません。 –

+0

私は実装したメソッドを追加しました。各画像の下のテキストフィールドであるラベルb/cを無視することができますが、hldImageは画像を保持する配列です。 – DJPlayer

関連する問題