編輯與正確的觀察。CATransform3應用錨點後效果消失
我用以下兩個片段來旋轉UIImageView。 stage1後,我得到了所需的3D效果:視圖旋轉(3D效果)和拉伸(更大的尺寸)。在舞臺2上,我試圖用右側的鉸鏈擺動右側的視圖。
如果我應用了更改定位點的線,視圖會正確擺動(右轉),但存在一個主要問題:視圖的大小恢復爲原始大小(較小),而(旋轉)3D效果仍然完好無損,然後發生擺動。
有什麼建議嗎?
rightView.layer.anchorPoint = CGPointMake(1.0, 0.5);
-(void)stage1
{
[UIView animateWithDuration:1.5 animations:^{
rightView.transform = CGAffineTransformMakeTranslation(0,0); //rightView i UIImageView
CATransform3D _3Dt = CATransform3DIdentity;
_3Dt =CATransform3DMakeRotation(3.141f/42.0f,0.0f,-1.0f,0.0f);
_3Dt.m34 = -0.001f;
_3Dt.m14 = -0.0015f;
rightView.layer.transform = _3Dt;
} completion:^(BOOL finished){
if (finished) {
NSLog(@"finished..");
}
}];
}
-(void)Stage2
{
rightView.layer.anchorPoint = CGPointMake(1.0, 0.5); //issue?
rightView.center = CGPointMake(1012, 384);
[UIView animateWithDuration:1.75 animations:^{
CATransform3D rightTransform = rightView.layer.transform;
rightTransform.m34 = 1.0f/500;
rightTransform = CATransform3DRotate(rightTransform, M_PI_2, 0, 1, 0);
rightView.layer.transform = rightTransform;
} completion:^(BOOL finished) {
}];
}
更改anchorpoint也改變被應用的變換方式。您能否在例如生成想要的結果的圖像? Photoshop的?初始狀態,stage1動畫完成時的狀態,stage2動畫完成時的狀態? – hfossli
@hfossli,添加圖片。我還在stage2動畫發生之前添加了一張圖片。請注意,我可以在stage2動畫之前使用setFrame改變rightView的框架,但我無法在stage1動畫之後使其與原始3D效果(角度等)相匹配。 – user523234
您上傳了所需圖像或「錯誤」輸出的圖像? – hfossli