我正在尝试调整 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。我在没有运气的情况下调整了所有值。我将感谢您的帮助,我喜欢图形编程,这对我来说是新的。
谢谢。