2012-03-12 22 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還是通過代碼初始化它? – 2012-03-12 12:58:08

+0

我在代碼中初始化。但我認爲這是關於carcarl的委託方法。我嘗試解決,但我是新手。我不明白所有的方法 – 2012-03-12 13:00:51

+0

正如我記得iCarousel有一個平移手勢識別器,它在整個視圖上工作。你可以發佈你的代碼片段,你設置旋轉木馬? – 2012-03-12 13:02:54

回答

0

我想你的iCarousel框架有問題 - 可能觸及其他元素在框架之外,並且iCarousel手勢識別器不會接收到觸摸。其他可能性是,您的視圖中的其他元素會觸及並且不會將其傳遞給iCarousel。 iCarousel旨在處理所有接觸(不僅來自主要元素)。正如我在您的帖子下方評論中所寫,您確定您的輪播設置一切正常嗎?

+0

是的,你是寫。非常感謝.. – 2012-03-12 14:39:04

-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個圖像。要開始動畫我必須滾動中心項目。如果我嘗試滾動其他圖像,它不起作用。動畫不會開始移動。 – 2012-03-12 13:17:41

+0

我添加了你已經實現的方法。你可以忽略我的標籤b/c這是每個圖像下的文本字段..但hldImage是一個數組,用於存放圖像。 – DJPlayer 2012-03-12 13:30:22