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{

    //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を助けるかもしれません。

于 2013-05-27T10:48:37.347 に答える
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 に答える