Hiding back images in iCarouselTypeRotary view for

2019-06-16 16:54发布

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.

5条回答
beautiful°
2楼-- · 2019-06-16 17:36

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.

查看更多
Melony?
3楼-- · 2019-06-16 17:38

You should implement the delegate:

- (CGFloat)carousel:(iCarousel *)_carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value{
 switch (option)
 {
    case iCarouselOptionVisibleItems:
    {
        return numberOfItemsIntheFront;
    }
 }
}
查看更多
我只想做你的唯一
4楼-- · 2019-06-16 17:44

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;
        }
    }
 }
查看更多
做个烂人
5楼-- · 2019-06-16 17:50

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
}
查看更多
太酷不给撩
6楼-- · 2019-06-16 17:58

I tried the solution suggested by @NickLockwood but doesn't seem to work :-( I added it to both methods in viewForItemAtIndex & placeholderViewAtIndex. My image size is 115*115 pixels and canvas size is 146*146 pixels. However, setting a return value of 'return value * 0.82f;' under iCarouselOptionSpacing (inside the method valueForOption) did the trick for me.

查看更多
登录 后发表回答