2012-04-16 209 views
1

我正在旋轉45度的箭頭。動畫結束時,箭頭返回到原始狀態(0度)。我需要箭頭不會回到原始狀態,它會在動畫結束時旋轉45度。旋轉動畫

CABasicAnimation *fullRotationShort = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 
fullRotationShort.fromValue = [NSNumber numberWithFloat:0]; 
fullRotationShort.toValue = [NSNumber numberWithFloat:M_PI/28*4.7]; 
fullRotationShort.duration = 1.0f; 
fullRotationShort.repeatCount = 1; 
[imgViewArrowShort.layer addAnimation:fullRotationShort forKey:nil]; 

回答

1

設置屬性:

fullRotationShort.fillMode = kCAFillModeForwards; 
fullRotationShort.cumulative = YES; 
    fullRotationShort.removedOnCompletion=NO; 
+0

這是行不通的。 – Sveta 2012-04-16 11:53:31

+0

哦,我忘記了一些行.....你再次檢查.. ?? – userar 2012-04-16 11:55:24

+0

謝謝!有用! – Sveta 2012-04-16 11:57:37

6

假設你的箭是一個UIImageView命名arrow
你真的不需要這樣複雜的CAAnimations。

[UIView animateWithDuration:1.0 animations:^{ 
    arrow.transform = CGAffineTransformMakeRotation(0.25 * M_PI); 
}]; 
+0

救了我的一天:)感謝這樣的簡單和優雅的解決方案。 – 2015-07-09 13:33:44