Ios 三维旋转时意外的CALayer垂直翻转';反弹';

Ios 三维旋转时意外的CALayer垂直翻转';反弹';,ios,objective-c,animation,core-animation,calayer,Ios,Objective C,Animation,Core Animation,Calayer,我正在尝试创建一个翻转转换,其中包含一个由CALayer单元格组成的网格,这些单元格翻转并在翻转后“反弹”。然而,我遇到了一个奇怪的垂直翻转问题,如所示。如果最后没有“反弹”动画,动画将按预期工作,因此与图像本身无关,也与在设置动画之前将图像拼接到各个单元层无关 动画代码(针对每个CALayer单元格) 初始化代码(在父级UIViewController中) -(instancetype)initWithStartImage:(UIImage*)startImage endImage:(UIIm

我正在尝试创建一个翻转转换,其中包含一个由
CALayer
单元格组成的网格,这些单元格翻转并在翻转后“反弹”。然而,我遇到了一个奇怪的垂直翻转问题,如所示。如果最后没有“反弹”动画,动画将按预期工作,因此与图像本身无关,也与在设置动画之前将图像拼接到各个单元层无关

动画代码(针对每个CALayer单元格)

初始化代码(在父级UIViewController中)

-(instancetype)initWithStartImage:(UIImage*)startImage endImage:(UIImage*)endImage{
if(self=[super init]){
CGFloat baseNodeHeight=screenWidth()/basenumberNodeWidth;
numNodeHeight=roundf(屏幕高度()/baseNodeHeight);
numNodeWidth=roundf(screenWidth()/baseNodeHeight);
moveUpdateFreq=moveBaseUpdateFreq/(节点宽度*节点高度);
cellMoveUpdateFreq=cellMoveBaseUpdateFreq/(NumNodeWidth*NumNodeHeight);
CGFloat const nodeWidth=screenWidth()/numNodeWidth;
CGFloat const nodeHeight=screenHeight()/numNodeHeight;
transition=(transitionType)arc4random_uniform(transitionTypeCount);
cellArray=[NSMutableArray];
对于(int x=0;x

知道我做错了什么吗?

好吧,我只能假设这是一个bug,但我已经找到了一个快速修复方法。通过在“反弹”动画中添加一个设置为从圆周率到圆周率的xRotation动画,问题得到了解决。例如,在反弹动画代码中:

// Bounce animation

CABasicAnimation* yRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
yRotation.toValue = @(M_PI+(M_PI*bounceFactor));
yRotation.fromValue = @(M_PI);

CABasicAnimation* zRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
zRotation.fromValue = @(0);
zRotation.toValue = @(-zRotateMax*_zRotateFactor*bounceFactor);

// New animation, set to do nothing on the x-axis
CABasicAnimation* xRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
xRotation.toValue = @(M_PI);
xRotation.fromValue = @(M_PI);

CAAnimationGroup* rotations = [CAAnimationGroup animation];
rotations.duration = 0.2;
rotations.removedOnCompletion = NO;
rotations.fillMode = kCAFillModeForwards;
rotations.delegate = self;
rotations.autoreverses = YES;
rotations.animations = @[yRotation, zRotation, xRotation];
[self addAnimation:rotations forKey:@"endRotate2"];

因此,
self
这里是
UITableViewCell
的一个子类?@Unheilig否,它们是
CALayer
的一个子类。很抱歉,在我发布其余代码之前,我已经断电了。
-(instancetype) initWithStartImage:(UIImage*)startImage endImage:(UIImage*)endImage {
    if (self = [super init]) {

        CGFloat baseNodeHeight = screenWidth()/baseNumberNodesWidth;

        numNodesHeight = roundf(screenHeight()/baseNodeHeight);
        numNodesWidth = roundf(screenWidth()/baseNodeHeight);

        moveUpdateFreq = moveBaseUpdateFreq/(numNodesWidth*numNodesHeight);
        cellMoveUpdateFreq = cellMoveBaseUpdateFreq/(numNodesWidth*numNodesHeight);

        CGFloat const nodeWidth = screenWidth()/numNodesWidth;
        CGFloat const nodeHeight = screenHeight()/numNodesHeight;

        transition = (transitionType)arc4random_uniform(transitionTypeCount);

        cellArray = [NSMutableArray array];

        for (int x = 0; x < numNodesWidth; x++) {

            [cellArray addObject:[NSMutableArray array]];

            for (int y = 0; y < numNodesHeight; y++) {

                transitionCell* c = [transitionCell layer];
                c.frame = (CGRect){{x*nodeWidth, y*nodeHeight}, {nodeWidth, nodeHeight}};

                CGRect startSubRect = {{c.frame.origin.x, screenHeight()-c.frame.origin.y-c.frame.size.height}, c.frame.size};
                CGRect endSubRect = {{c.frame.origin.x, c.frame.origin.y}, c.frame.size};

                c.startImage = [startImage imageFromSubRect:startSubRect];
                c.endImage = [[endImage flippedVerticalImage] imageFromSubRect:endSubRect];

                c.zRotateFactor = -(((CGFloat)y-((CGFloat)numNodesHeight*0.5))/(CGFloat)numNodesHeight);

                [self.view.layer addSublayer:c];
                [cellArray[x] addObject:c];

            }
        }

    }
    return self;
}
// Bounce animation

CABasicAnimation* yRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
yRotation.toValue = @(M_PI+(M_PI*bounceFactor));
yRotation.fromValue = @(M_PI);

CABasicAnimation* zRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
zRotation.fromValue = @(0);
zRotation.toValue = @(-zRotateMax*_zRotateFactor*bounceFactor);

// New animation, set to do nothing on the x-axis
CABasicAnimation* xRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
xRotation.toValue = @(M_PI);
xRotation.fromValue = @(M_PI);

CAAnimationGroup* rotations = [CAAnimationGroup animation];
rotations.duration = 0.2;
rotations.removedOnCompletion = NO;
rotations.fillMode = kCAFillModeForwards;
rotations.delegate = self;
rotations.autoreverses = YES;
rotations.animations = @[yRotation, zRotation, xRotation];
[self addAnimation:rotations forKey:@"endRotate2"];