Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding back images in iCarouselTypeRotary view for iCarousel

I have set images in iCarousel. When I scroll the carousel, it shows images in front and back. I do not want to display images in back. Please help. Thank you.

like image 217
iPhone Developer Avatar asked Feb 21 '12 12:02

iPhone Developer


4 Answers

You should implement the delegate:

- (CGFloat)carousel:(iCarousel *)_carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value{
 switch (option)
 {
    case iCarouselOptionVisibleItems:
    {
        return numberOfItemsIntheFront;
    }
 }
}
like image 190
dtochetto Avatar answered Oct 17 '22 08:10

dtochetto


You'll need to change to a custom carousel type, and copy the implementation of iCarouselTypeRotary in your delegate. Then implement -carousel:itemAlphaForOffset: so that items around the back have an alpha of zero.

like image 33
Simon Avatar answered Oct 17 '22 09:10

Simon


In the latest version of iCarousel, the easiest way to do this is to set view.layer.doubleSided = NO on your carousel item views, or to use the iCarouselOptionShowBackfaces property, like this:

- (CGFloat)carousel:(iCarousel *)_carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
    switch (option)
    {
        case iCarouselOptionShowBackfaces:
        {
            return NO;
        }
        default:
        {
            return value;
        }
    }
 }
like image 3
Nick Lockwood Avatar answered Oct 17 '22 08:10

Nick Lockwood


Code below will nicely fade away items that are going to the back. Enjoy.

func carousel(carousel: iCarousel, valueForOption option: iCarouselOption, withDefault value: CGFloat) -> CGFloat
{
    if (option == .Spacing)
    {
        return value * 1.1
    }
    else if (option == .FadeMin)
    {
        return 0;
    }
    else if (option == .FadeMax)
    {
        return 0;
    }
    else if (option == .FadeRange)
    {
        return 3;
    }

    return value
}
like image 2
Rafa de King Avatar answered Oct 17 '22 09:10

Rafa de King