2013-05-27 55 views
0

我有一個數組,其中包含20個圖像使用滾動視圖將圖像添加到imageview。所有圖像滾動。Integrate Carousel For ImageView

我想爲我所有的20張圖片添加旋轉木馬圈效果我該怎麼做?我已經試過這個但不行。

將iCarousel.h,iCarousel.m添加到定義委託的包中。

<iCarouselDataSource,iCarouselDelegate,UIScrollViewDelegate> 

-(void)viewDidLoad 
{ 
iCarousel *icrusal = [[iCarousel alloc]initWithFrame:CGRectMake(0,0, 320, 480)]; 

    icrusal.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
    icrusal.delegate = self; 
    icrusal.dataSource = self; 
    icrusal.type=iCarouselTypeRotary; 

    icrusal.type=iCarouselTypeCoverFlow; 

    [self.view addSubview:icrusal]; 
} 

-(NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel 
{ 

    return 20; 
} 


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

    //ImgView=[[UIImageView alloc]init]; 

    ImgView=[[UIImageView alloc]init]; 

    return ImgView; 

} 

- (BOOL)carousel:(iCarousel *)carousel shouldSelectItemAtIndex:(NSInteger)index{ 


    return YES; 
} 
- (CGFloat)carouselItemWidth:(iCarousel *)carousel 
{ 
    //usually this should be slightly wider than the item views 
    return 180; 
} 

我該怎麼做,這在此先感謝。

+0

此編碼是正確的或缺少某些東西。 – Vasu

+0

我想對我的圖像有圓形效果。意味着20顯示1 2 3 ...圖像之後。 – Vasu

回答

0
- (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, 50.0f, 50.0f)]; 
     ((UIImageView *)view).image = [UIImage imageNamed:@"apple-logo-1.png"]; 
     view.contentMode = UIViewContentModeCenter; 
    } 
    else 
    { 
     //get a reference to the label in the recycled view 
     ((UIImageView *)view).image = [UIImage imageNamed:@"apple-logo-1.png"]; 
    } 
    return view; 

} 

而且你還可以添加以下方法給在iCarousel

- (CGFloat)carousel:(iCarousel *)_carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value 
{ 
    //customize carousel display 
    switch (option) 
    { 
     case iCarouselOptionWrap: 
     { 
      //normally you would hard-code this to YES or NO 
      return NO; 
     } 
     case iCarouselOptionSpacing: 
     { 
      //add a bit of spacing between the item views 
      return value * 1.95f; 
     } 
     case iCarouselOptionFadeMax: 
     { 
      if (_carousel.type == iCarouselTypeCustom) 
      { 
       //set opacity based on distance from camera 
       return 0.0f; 
      } 
      return value; 
     } 
     default: 
     { 
      return value; 
     } 
    } 
} 

這可能有助於YPU圖像之間的空間。

+0

我想爲我的圖像視圖添加循環效果。 – Vasu

+0

刪除icrusal.type = iCarouselTypeCoverFlow;這從你的代碼並嘗試 – LittleIDev

+0

icrusal.type = iCarouselTypeRotary;這條線可以給你圓形效果 – LittleIDev

0
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view 
{ 
if (view == nil) 
{ 
NSString *strStarImg=[[yourarrayofImage objectAtIndex:index] valueForKey:@"keyofImage"]; 

ImgView = [UIImageView alloc] initWithImage:[UIImage imageNamed:strStarImg]; 
//you can define frame of your imageview here...ImgView.frame=CGRectMake(0, 450, 768, 462); 
[view addSubview:img]; 
return view; 
} 

讓我知道這是工作或不.. !!

快樂編碼.... !!!