Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iCarousel centered item's position (iOS)

I am using iCarousel framework, i made it custom, my carousel is vertical, centered item is bigger and has space around it. My problem is - I can't find how to make centered item not centered, I need to move it slightly up. Here is my code:

- (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; }
like image 351
Ignas S Avatar asked Apr 11 '26 13:04

Ignas S


1 Answers

Try this:

- (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;
}
like image 91
Nick Lockwood Avatar answered Apr 13 '26 01:04

Nick Lockwood



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!