3

我正在使用 iCarousel 框架,我定制了它,我的旋转木马是垂直的,居中的项目更大并且周围有空间。我的问题是 - 我找不到如何使居中的项目不居中,我需要稍微向上移动它。这是我的代码:

- (CATransform3D)carousel:(iCarousel *)carousel itemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform {

    const CGFloat centerItemZoom = 1.6;
    const CGFloat centerItemSpacing = 1.5;

    CGFloat spacing = [self carousel:carousel valueForOption:iCarouselOptionSpacing withDefault:1.0f];
    CGFloat absClampedOffset = MIN(1.0, fabs(offset));
    CGFloat clampedOffset = MIN(1.0, MAX(-1.0, offset));
    CGFloat scaleFactor = 1.0 + absClampedOffset * (1.0/centerItemZoom - 1.0);
    offset = (scaleFactor * offset + scaleFactor * (centerItemSpacing - 1.0) * clampedOffset) * carousel.itemWidth * spacing;

    if (carousel.vertical)
    {
        transform = CATransform3DTranslate(transform, 0.0f, offset, -absClampedOffset);
    }
    else
    {
        transform = CATransform3DTranslate(transform, offset, 0.0f, -absClampedOffset);
    }

    transform = CATransform3DScale(transform, scaleFactor, scaleFactor, 2.0f);

    return transform; }
4

1 回答 1

4

试试这个:

- (CATransform3D)carousel:(iCarousel *)carousel itemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform {

    const CGFloat centerItemZoom = 1.6;
    const CGFloat centerItemSpacing = 1.5;
    const CGFloat centerItemYOffset = -50;

    CGFloat spacing = [self carousel:carousel valueForOption:iCarouselOptionSpacing withDefault:1.0f];
    CGFloat absClampedOffset = MIN(1.0, fabs(offset));
    CGFloat clampedOffset = MIN(1.0, MAX(-1.0, offset));
    CGFloat scaleFactor = 1.0 + absClampedOffset * (1.0/centerItemZoom - 1.0);
    CGFloat yoffset = (1.0f - absClampedOffset) * centerItemYOffset;
    offset = (scaleFactor * offset + scaleFactor * (centerItemSpacing - 1.0) * clampedOffset) * carousel.itemWidth * spacing;

    if (carousel.vertical)
    {
        transform = CATransform3DTranslate(transform, yoffset, offset, -absClampedOffset);
    }
    else
    {
        transform = CATransform3DTranslate(transform, offset, yoffset, -absClampedOffset);
    }

    transform = CATransform3DScale(transform, scaleFactor, scaleFactor, 2.0f);

    return transform;
}
于 2013-11-08T13:36:51.580 回答