Heena
Heena

Reputation: 2358

iCarousel is getting stick when starting to scroll

Getting stick hereI have implemented iCarousel's this methods as,

It is getting stick at beginning and after seconds it allows me to scroll. And also i don't want the images to be overlapped while scrolling i want them all to be having equal distance between each item.

What is wrong in this code? or i am missing anything?

-(void)addiCarousel
{
    carousel.frame = CGRectMake(324, 50, 375, 195);
    [self.view addSubview:carousel];
    self.items = [[NSMutableArray alloc] initWithObjects:@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg",@"5.jpg", nil];
    carousel.type = iCarouselTypeCoverFlow2;
    [carousel reloadData];
}

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    return [items count];
}

- (BOOL)carouselShouldWrap:(iCarousel *)carousel
{
    return NO;
}

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

 //   if (view == nil)
   // {
        view = [[[UIImageView alloc] initWithFrame:CGRectMake(649, 50, 375 , 195)] autorelease];
        view.contentMode = UIViewContentModeCenter;
        view.layer.borderWidth = 8.0f;
        view.layer.borderColor = [[UIColor blackColor] CGColor];
    view.contentMode = UIViewContentModeScaleToFill;

//    }

     ((UIImageView *)view).image = [UIImage imageNamed:[self.items objectAtIndex:index]];

    NSLog(@"index : %d",index);
    NSLog(@"%@",[self.items objectAtIndex:index]);

    return view;
}

Upvotes: 0

Views: 1614

Answers (3)

Heena
Heena

Reputation: 2358

After adding below code it stop getting stick and gave smooth scrolling

It was missing,

- (CATransform3D)carousel:(iCarousel *)_carousel transformForItemView:(UIView *)view withOffset:(CGFloat)offset
{
    //implement 'flip3D' style carousel

    //set opacity based on distance from camera
    view.alpha = 1.0 - fminf(fmaxf(offset, 0.0), 1.0);

    //do 3d transform
    CATransform3D transform = CATransform3DIdentity;
    transform.m34 = carousel.perspective;
    transform = CATransform3DRotate(transform, M_PI / 8.0, 0, 1.0, 0);
    return CATransform3DTranslate(transform, 0.0, 0.0, offset * carousel.itemWidth);
}

along with carousel.clipsToBounds = YES;

Might help others.

Upvotes: 0

Nick Lockwood
Nick Lockwood

Reputation: 40995

Try deleting the reloadData call after creating the carousel, and instead add the carousel as a subview after you've set up the items array.

Upvotes: 0

vishy
vishy

Reputation: 3231

have you used the below method

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

this info is given in the tutorial.. and you can use

    [carousal scrollToItemAtIndex:3 animated:NO];

so that it shows the 3 pic at the centre.

Upvotes: 2

Related Questions