UIView動畫是動畫視圖的屬性,而不是動畫層。據我所知,你不能使用UIView animateWithDuration:call爲視圖的層設置動畫。
您需要創建一個CABasicAnimation並將其自己添加到視圖的圖層中。
這已經有一段時間,因爲我做了CAAnimations,但讓我們看看我能挖:作爲atxe說
,你應該做這個動畫之前圖層的錨點移動到1 .5,所以它圍繞右邊緣旋轉。
這裏是我們的「凱文&凱爾」動畫片的應用程序,但這門的動畫擺動它的鉸鏈開一些代碼:
//Open the door.
rotateAnimation = [CABasicAnimation animation];
rotateAnimation.keyPath = @"transform";
rotateAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
//Pivot on the right edge (y axis rotation)
theTransform = CATransform3DIdentity;
theTransform.m34 = -1/100.0;
theTransform = CATransform3DRotate(theTransform, degreesToRadians(70), 0, 1, 0);
rotateAnimation.toValue = [NSValue valueWithCATransform3D:theTransform];
rotateAnimation.duration = 0.5;
// leaves presentation layer in final state; preventing snap-back to original state
rotateAnimation.removedOnCompletion = NO;
rotateAnimation.fillMode = kCAFillModeBoth;
rotateAnimation.repeatCount = 0;
rotateAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
rotateAnimation.delegate = self;
[treeDoorImageView.layer addAnimation:rotateAnimation forKey:@"transform"];
變換邏輯幾乎是相同的你(我用的-1/100一個更誇張的3D效果的M34值。你-1/500設置是比較正常的。)
注意,而不是試圖做從一個UIView動畫塊的動畫,我創建了一個CABasicAnimation,並將其從Value和toValue屬性設置爲開始和結束變換值。
您應該可以使用此代碼作爲動畫的起點。
您是否嘗試更改錨點? http://stackoverflow.com/questions/7438385/ios-rotate-view-around-an-anchor-point-and-follow-touch – atxe