iCarousel 居中项目的位置 (iOS)
Posted
技术标签:
【中文标题】iCarousel 居中项目的位置 (iOS)【英文标题】:iCarousel centered item's position (iOS) 【发布时间】:2013-11-08 09:32:11 【问题描述】:我正在使用 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;
【问题讨论】:
【参考方案1】:试试这个:
- (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;
【讨论】:
以上是关于iCarousel 居中项目的位置 (iOS)的主要内容,如果未能解决你的问题,请参考以下文章