带有自定义动画的Carousel,如Android 6运行应用程序列表

时间:2016-07-01 14:25:39

标签: ios objective-c icarousel

如何实现像Android 6运行应用程序列表一样的iCarousel?

我能做的最好的事情是:

- (CATransform3D)carousel:(__unused iCarousel *)carousel itemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform
{
      return CATransform3DTranslate(transform, 0.0f, 0.0f, offset * self.carousel.itemWidth);
}

1 个答案:

答案 0 :(得分:0)

这给你一个漂亮的外观,像洗牌一样透视:

- (CATransform3D)carousel:(__unused iCarousel *)carousel itemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform
{
    transform = CATransform3DScale(transform, 1.0f + offset / 30.0f, 1.0f, 1.0f);
    return CATransform3DTranslate(transform, 0.0f, offset * 20.0f, offset);
}

这里有几点调整:

- (CGFloat)carousel:(__unused iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
    switch (option)
    {
        case iCarouselOptionWrap:
        {
            return YES;
         }
        case iCarouselOptionSpacing:
       {

        return value * 1.5f;
        }
    case iCarouselOptionShowBackfaces:
    case iCarouselOptionRadius:
    case iCarouselOptionAngle:
    case iCarouselOptionArc:
    case iCarouselOptionTilt:
    case iCarouselOptionCount:
    {
        return value;
    }
    case iCarouselOptionFadeMax:
    {
        return value;
    }
    case iCarouselOptionFadeMin:
    {
        return 1.0f;
    }
    case iCarouselOptionFadeMinAlpha:
    {
        return 0.5f;
    }
    case iCarouselOptionFadeRange:
    {
        return value;
    }
    case iCarouselOptionOffsetMultiplier:
    {
        return 3.0f;
    }
    case iCarouselOptionVisibleItems:
    {
        return 3.0f;
    }
  }
}