我正在嘗試做一個帶有反彈效果的簡單水平翻轉動畫。CATransform3DMakeRotation動畫槽零(從-45到+45角度)?
[UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationCurveEaseIn animations:^{
front.layer.transform=CATransform3DMakeRotation(DEGREES_TO_RADIANS(90), -1.0,0.0,0.0); // flip halfway
}
completion:^(BOOL finished) { // swap view
front.alpha=0;
back.alpha=1;
[UIView animateWithDuration:0.5 animations:^{ // flip remaining + bounce
back.layer.transform = CATransform3DMakeRotation(DEGREES_TO_RADIANS(45), 1.0,0.0,0.0); // final + 45
}
completion:^(BOOL finished) {
[UIView animateWithDuration:0.25 animations:^{
back.layer.transform = CATransform3DMakeRotation(DEGREES_TO_RADIANS(-22.5), 1.0,0.0,0.0); // bounce back
}
completion:^(BOOL finished) {
[UIView animateWithDuration:0.125 animations:^{
back.layer.transform = CATransform3DMakeRotation(0, 1.0,0.0,0.0); // final
}];
}];
}];
}];
除了'反彈'以外,它的效果很好。 -22.5旋轉轉變爲0並且返回到22.5,而不是繼續到-22.5。
我已經嘗試過各種值,並且還包括一箇中間嵌套塊,在消極之前將反彈轉換爲「0」。沒有幫助。旋轉總是動畫爲正面而不是負面角度。
就像測試一樣,將'final + 45'改變爲負角度並不會停止所需角度的動畫。所以角度本身就沒問題。
問題似乎是從零開始或向低谷零做'逆時針'旋轉。小於零的值總是轉換爲正角。
如果上述方法是實現反射效果的正確技術,那麼將如何構建通過CATransform3DMakeRotation從正(45)旋轉到負角(-45)的(嵌套)層動畫?
謝謝!當用z訪問測試時,我可以看到旋轉確實工作正常。當您在x軸上「反彈」視圖時,我會加入視角,看看我是否被視錯覺所矇蔽。然而,看起來這樣... – Frans
工作。彈跳效果現在很好用! – Frans