0

我有一个包含 20 个图像的数组,使用滚动视图将该图像添加到 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;
}

我怎么能这样做提前谢谢。

4

2 回答 2

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;
}

让我知道它是否有效..!!

快乐编码....!!!

于 2013-05-27T10:38:48.943 回答
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;
        }
    }
}

这可能对你有帮助。

于 2013-05-27T10:48:37.347 回答