1

嗨,我在我的应用程序中包含了 iCarousel 以显示视图列表。我现在面临一个问题。

  1. 如果我将可见项目数设置为 3,则显示 3 索引视图的倍数
  2. 如果我没有设置显示 icarousel 视图的第一个和最后一个索引。

我对 iCarousel 中重用视图的概念感到非常困惑。

这是我的代码

-(void)viewWillAppear:(BOOL)animated
{



ViewArray=[[NSMutableArray alloc]init];
for (int i=0; i<26; i++) {
 [ViewArray addObject:views];
    [carousel1 reloadData];

}
NSLog(@"%@",ViewArray);
}


- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
//return the total number of items in the carousel
return 26;
}


- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
 UIView *sub=nil;
 if (view==nil) {


view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 900, 387)];

    capitalBG.frame=CGRectMake(28, 29, 221, 329);
    capitalBG.tag=11;
    [view addSubview:capitalBG];

    capitalImage.frame=CGRectMake(28, 29, 221, 329);
           [view addSubview:capitalImage];
    capitalImage.tag=12;
    smallBG.frame=CGRectMake(678, 111, 198, 166);
           [view addSubview:smallBG];
    smallBG.tag=21;
    smallImage.frame=CGRectMake(678, 111, 198, 166);
           [view addSubview:smallImage];
    smallImage.tag=22;

}

else
{

}

capitalBG.frame=CGRectMake(28, 29, 221, 329);
[capitalBG setImage:[UIImage imageNamed:@""]];
[view addSubview:capitalBG];

capitalImage.frame=CGRectMake(28, 29, 221, 329);
[capitalImage setImage:[[[Global ImageCollection]objectForKey:@"CapitalWrite"]objectAtIndex:index]];
[view addSubview:capitalImage];

smallBG.frame=CGRectMake(678, 111, 198, 166);
[smallBG setImage:[UIImage imageNamed:@""]];
[view addSubview:smallBG];

smallImage.frame=CGRectMake(678, 111, 198, 166);
[smallImage setImage:[[[Global ImageCollection]objectForKey:@"SmallWrite"]objectAtIndex:index]];
[view addSubview:smallImage];
 return view;
}


- (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
if (option == iCarouselOptionSpacing)
{
    return value * 1.1f;
}

if (option==iCarouselOptionVisibleItems) {
    return 3;
}
return value;
}
4

1 回答 1

2

我没有清楚地得到你要求的东西。检查 I-carousal 的实现代码以显示图像。

     - (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
  {
//add all your images to an array,and use that array for count. 

return [items count];
 }



     - (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index     reusingView:(UIView *)view
  {
    //create new view if no view is available for recycling
if (view == nil)
{
    view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 215.0f, 155.0f)];
    ((UIImageView *)view).image = [UIImage imageNamed:[self.items objectAtIndex:index ]];

    view.contentMode = UIViewContentModeCenter;
}

return view;

}

   - (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option          withDefault:(CGFloat)value
   {
//customize carousel display

        return value+0.1;
     }
于 2013-02-19T11:11:30.783 回答