Objective c 调整伊卡鲁塞尔
我正试图调整iCarousel以实现此旋转木马: 我用的是伊卡鲁塞尔: 以下是我目前的工作: 所以我现在需要做的是改变旋转木马的视角,放大中心项目。我有点迷路了,发现这篇文章和同一个问题有关: 所以我用这种方式修改了iCarousel类:Objective c 调整伊卡鲁塞尔,objective-c,ios5,Objective C,Ios5,我正试图调整iCarousel以实现此旋转木马: 我用的是伊卡鲁塞尔: 以下是我目前的工作: 所以我现在需要做的是改变旋转木马的视角,放大中心项目。我有点迷路了,发现这篇文章和同一个问题有关: 所以我用这种方式修改了iCarousel类: - (CATransform3D)transformForItemView:(UIView *)view withOffset:(CGFloat)offset { //set up base transform CATransfor
- (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。我调整了所有的值,但没有运气。我会感谢你的帮助,我喜欢图形编程,这对我来说是新的
谢谢。以下是如何使效果接近您想要达到的效果:
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
,然后在代理中返回变换旋转木马:itemTransformForOffset:baseTransform:
是否检查了半径和可见项的数量?如何更改?我检查了不同的iCarousel属性,但找不到半径或可见项。非常感谢,非常感谢塞吉奥!顺便说一句,你能给出一些关于深度缩放效应和深度倾斜的指导吗?我将不胜感激。@sergio您能告诉我在哪里可以放置此代码吗?@MaulikVekariya:正如我所建议的,正确的方法是使用iCarouselTypeCustom
carousel并从代理的carousel:itemTransformForOffset:baseTransform:
返回我在上面定义的转换。如果您更喜欢破解iCarousel源代码,只需修改上面的transformForItemView:
方法。您是如何根据偏移量设置项目的alpha的?