我正在使用 Nick Lockwood 旋转木马,类型是 Wheel Carousel。我将图像用作轮播中的项目。问题是当我旋转旋转木马时,图像也会旋转,即考虑人物图像,然后人物图像会倾斜,这是我不想要的,即我不想在旋转整个旋转木马时旋转该特定图像。有人可以帮忙吗?
问问题
739 次
4 回答
4
查看- (CATransform3D)transformForItemView:(UIView *)view withOffset:(CGFloat)offset;
Find case iCarouselTypeWheel:
andcase 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);
我希望这会有所帮助。
于 2012-07-24T14:18:08.647 回答
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);
看看会发生什么;我猜这个脸不会被旋转,但是你可能需要调整翻译......
于 2012-06-15T13:57:21.067 回答
0
尝试根据设备方向有条件地旋转图像
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view;
委托方法。
于 2012-06-15T13:39:05.573 回答
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);
}
于 2017-07-31T17:08:44.803 回答