我正在尝试调整iCarousel以实现此轮播:
我正在使用iCarousel:https://github.com/nicklockwood/iCarousel
这是我目前的工作:
所以我现在需要做的是改变轮播视角并扩大中心项目。我有点失落,发现这篇文章与同一个问题有关:
所以我用这种方式修改了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。我正在调整所有的价值而没有运气。我将非常感谢你的帮助,我喜欢图形编程,这对我来说是新的。
感谢。
答案 0 :(得分: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
,而是需要将轮播转换为iCarouselTypeCustom
,然后在委托carousel:itemTransformForOffset:baseTransform:
中返回转换。