我試圖通過旋轉超過180度來動畫移動的儀表,但它不會工作。 Im使用CGAffineTransform
旋轉儀表,該儀表使用淨結果進行旋轉。這意味着使用此功能時我不能選擇CW或CCW旋轉。我如何修改此代碼以使其旋轉4弧度。目前,旋轉被轉換爲淨結果,使旋轉最小化。在iOS上使用動畫旋轉UIImageView超過180度
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
CGAffineTransform transform = CGAffineTransformMakeRotation(4);
self.meter.transform = transform;
[UIView commitAnimations];
編輯: 從我設法得到它的工作通過這樣
[UIView animateWithDuration:1.5 animations:^{
CABasicAnimation *fullRotation;
fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:((330*M_PI)/180)];
fullRotation.duration = 2.0f;
fullRotation.repeatCount = 1;
fullRotation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
fullRotation.fillMode = kCAFillModeForwards;
fullRotation.removedOnCompletion = NO;
// add animation in your view
[self.meter.layer addAnimation:fullRotation forKey:@"330"];
[self performSelector:@selector(stopRotate:) withObject:self.meter afterDelay:2.0];
}];
此答案無法正常工作,但我設法通過編輯來獲得它的工作,請參閱我的編輯。 – Zeezer