1

我正在尝试调整 iCarousel 以实现此轮播:

在此处输入图像描述

我正在使用 iCarousel:https ://github.com/nicklockwood/iCarousel

这是我目前的工作:

在此处输入图像描述

所以我现在需要做的是改变轮播视角并放大中心项目。我有点迷茫,发现这篇文章与同一问题有关:

iPhone - 轮播

所以我以这种方式修改了 iCarousel 类:

- (CATransform3D)transformForItemView:(UIView *)view withOffset:(CGFloat)offset
{   
    //set up base transform
    CATransform3D transform = CATransform3DIdentity;
    transform.m34 = _perspective;
    transform = CATransform3DTranslate(transform, -_viewpointOffset.width, -_viewpointOffset.height, 0.0f);

    //perform transform
    switch (_type)
    {
        case iCarouselTypeCustom:
        {
            if ([_delegate respondsToSelector:@selector(carousel:itemTransformForOffset:baseTransform:)])
            {
                return [_delegate carousel:self itemTransformForOffset:offset baseTransform:transform];
            }

            //else, fall through to linear transform
        }
        case iCarouselTypeLinear:
        {
            CGFloat spacing = [self valueForOption:iCarouselOptionSpacing withDefault:1.0f];
            if (_vertical)
            {
                return CATransform3DTranslate(transform, 0.0f, offset * _itemWidth * spacing, 0.0f);
            }
            else
            {
                return CATransform3DTranslate(transform, offset * _itemWidth * spacing, 0.0f, 0.0f);
            }
        }
        case iCarouselTypeRotary:
        {
            CGFloat count = [self circularCarouselItemCount];
            CGFloat spacing = [self valueForOption:iCarouselOptionSpacing withDefault:1.0f];
            CGFloat arc = [self valueForOption:iCarouselOptionArc withDefault:M_PI * 2.0f];
            CGFloat radius = [self valueForOption:iCarouselOptionRadius withDefault:fmaxf(_itemWidth * spacing / 2.0f, _itemWidth * spacing / 2.0f / tanf(arc/2.0f/count))];
            CGFloat angle = [self valueForOption:iCarouselOptionAngle withDefault:offset / count * arc];

            if (_type == iCarouselTypeInvertedRotary)
            {
                radius = -radius;
                angle = -angle;
            }

            if (_vertical)
            {
                return CATransform3DTranslate(transform, 0.0f, radius * sin(angle), radius * cos(angle) - radius);
            }
            else
            {
                float MAX_TILT_VALUE = 3.0f;
                float tilt = MAX_TILT_VALUE * cos(angle); // greater angle means greater vertical offset
                return CATransform3DTranslate(transform, radius * sin(angle), tilt, radius * cos(angle) - radius);
            }
        }

顺便说一句,我正在使用 iCarouselTypeRotary。我在没有运气的情况下调整了所有值。我将感谢您的帮助,我喜欢图形编程,这对我来说是新的。

谢谢。

4

1 回答 1

2

以下是如何使效果接近您想要达到的效果:

    case iCarouselTypeInvertedRotary:
    {
        ...
        //-- you might need to multiply radius by a certain factor to make the carousel appear denser:
        CGFloat radius = 0.35 * [self valueForOption:iCarouselOptionRadius withDefault:fmaxf(_itemWidth * spacing / 2.0f, _itemWidth * spacing / 2.0f / tanf(arc/2.0f/count))];

        ...

        else
        {

            //-- for the not inverted case, you need to add
            //-- an y-axis translation factor to add depth-tilting of the carousel plane
            //-- + a factor to increase depth-scaling effect:

            return CATransform3DTranslate(transform,
                            radius * sin(angle),
                            0.5 * radius * cos(angle),
                            2.0 * (radius * cos(angle) - radius));
        }
    }

我使用了您可能需要调整以获得正确效果的示例值。

顺便说一句,这样做的正确方法不是修改transformForItemView,而是您需要将轮播变成 aiCarouselTypeCustom然后在您的委托中返回转换carousel:itemTransformForOffset:baseTransform:

于 2013-01-16T11:01:39.033 回答