2013-06-28 185 views
0

我旋轉與下面的代碼的UIImageView:核心動畫setFromValue

CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 
[rotate setFromValue:[NSNumber numberWithFloat:0.0]]; 
[rotate setToValue:[NSNumber numberWithFloat:-0.34906585)]]; 
[rotate setDuration:0.8]; 
[rotate setTimingFunction:[CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut]]; 
rotate.removedOnCompletion = NO; 
rotate.fillMode = kCAFillModeForwards; 
[myUIImageView.layer addAnimation:rotate forKey:@"dangleMyDial"]; 

但每次我調用此函數就開始轉動,從原來的位置的圖像。我應該使用什麼[旋轉setFromValue:];使它從目前的位置旋轉?有沒有顯示當前角度的屬性?

(0.34906585拉德等於20Deg)

+0

會發生什麼,當你只是取消對'setFromValue'和使用'的byValue'代替'toValue'? – Danilo

+0

我試過了,同樣的事情。它將從原始位置開始(aka 0deg) – Mojtaba

+0

不能跟蹤已經對變量進行的旋轉量嗎? – Danilo

回答

1
CATransform3D transform = ((CALayer *) self.myUIImageView.layer.presentationLayer).transform; 
CGFloat startAngle = atan2(transform.m12, transform.m11); 

CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 
[rotate setFromValue:[NSNumber numberWithFloat:startAngle]]; 
[rotate setByValue:[NSNumber numberWithFloat:-20 * M_PI/180]]; 

// ...