gpt4 book ai didi

ios - iCarousel 居中项目的位置 (iOS)

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:47:19 32 4
gpt4 key购买 nike

我正在使用 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; }

最佳答案

试试这个:

- (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;
}

关于ios - iCarousel 居中项目的位置 (iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19855632/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com