我正在使用Nick Lockwood旋转木马,类型是Wheel Carousel。我使用图像作为旋转木马中的项目。问题是当我旋转旋转木马时图像也旋转,即考虑人物图像,然后人物图像倾斜,这是我不想要的,即我不想在旋转整个旋转木马时旋转该特定图像。有人可以帮忙吗?
答案 0 :(得分:4)
查看- (CATransform3D)transformForItemView:(UIView *)view withOffset:(CGFloat)offset;
的实施内容查找case iCarouselTypeWheel:
和case iCarouselTypeInvertedWheel:
阻止。
更改生成最终变换的代码(对于垂直和水平情况)以反转应用的旋转:
transform = CATransform3DTranslate(transform, 0.0f, radius, 0.0f);
transform = CATransform3DRotate(transform, angle * offset, 0.0f, 0.0f, 1.0f);
// this is the transform the existing code returns...
transform = CATransform3DTranslate(transform, 0.0f, -radius, offset * 0.01f);
// instead you reverse the rotation before returning...
return CATransform3DRotate(transform, -(angle * offset), 0.0f, 0.0f, 1.0f);
我希望有所帮助。
答案 1 :(得分:1)
查看文件iCarousel.m,找到- (CATransform3D)transformForItemView:(UIView *)view withOffset:(CGFloat)offset
方法;你可以在里面找到这个块:
case iCarouselTypeWheel:
case iCarouselTypeInvertedWheel:
{
NSInteger count = [self valueForTransformOption:iCarouselTranformOptionCount withDefault:
MIN(numberOfVisibleItems, numberOfItems + numberOfPlaceholdersToShow)];
CGFloat arc = [self valueForTransformOption:iCarouselTranformOptionArc withDefault:M_PI * 2.0f];
CGFloat radius = [self valueForTransformOption:iCarouselTranformOptionRadius withDefault:itemWidth * (CGFloat)count / arc];
CGFloat angle = [self valueForTransformOption:iCarouselTranformOptionAngle withDefault:arc / (CGFloat)count];
if (type == iCarouselTypeInvertedWheel)
{
radius = -radius;
angle = -angle;
}
if (vertical)
{
transform = CATransform3DTranslate(transform, -radius, 0.0f, 0.0f);
/* this */ transform = CATransform3DRotate(transform, angle * offset, 0.0f, 0.0f, 1.0f);
return CATransform3DTranslate(transform, radius, 0.0f, offset * 0.01f);
}
else
{
transform = CATransform3DTranslate(transform, 0.0f, radius, 0.0f);
/* this */ transform = CATransform3DRotate(transform, angle * offset, 0.0f, 0.0f, 1.0f);
return CATransform3DTranslate(transform, 0.0f, -radius, offset * 0.01f);
}
}
尝试简单地注释掉两行:
transform = CATransform3DRotate(transform, angle * offset, 0.0f, 0.0f, 1.0f);
看看会发生什么;我想面部不会旋转,但是你可能需要调整翻译......
答案 2 :(得分:0)
尝试根据
中的设备方向有条件地旋转图像- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view;
委托方法。
答案 3 :(得分:0)
使用上述答案中的代码,我无法真正解决问题。我重复使用了部分注释,但没有使用代码。对我有用的是这个。
if (_vertical)
{
transform = CATransform3DTranslate(transform, -radius, 0.0, 0.0);
transform = CATransform3DRotate(transform, angle * offset, 0.0, 0.0, 1.0);
transform = CATransform3DTranslate(transform, radius, 0.0, offset * 0.01);
return CATransform3DRotate(transform, -(angle * offset), 0.0, 0.0, 1.0);
}
else
{
transform = CATransform3DTranslate(transform, 0.0, radius, 0.0);
transform = CATransform3DRotate(transform, angle * offset, 0.0, 0.0, 1.0);
transform = CATransform3DTranslate(transform, 0.0, -radius, offset * 0.01);
return CATransform3DRotate(transform, -(angle * offset), 0.0, 0.0, 1.0);
}