我的交易开始缓慢,变得快,然后变慢。 我需要整个线速度。
我找到UIViewAnimationOptionCurveLinear
但找不到[CATransaction begin]
这是我的代码:
[ CATransaction begin ];
if( graph_animation_enable )
[CATransaction setAnimationDuration: graph_animation_seconds ];
else
[CATransaction setAnimationDuration: 0 ];
//[CATransaction setValue : ( id ) kCFBooleanTrue forKey : kCATransactionDisableActions];
graph_CALayer.frame = CGRectMake( left_x, top_y, width, height );
graph_CALayer.backgroundColor = bar_background_color.CGColor;
CAMediaTimingFunction *linearTiming =
[CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear];
[CATransaction setAnimationTimingFunction: linearTiming];
[CATransaction commit];
我试过了答案,但仍然是非线性的。 动画开始,但随后变慢。
答案 0 :(得分:0)
使用CATransaction
setAnimationTimingFunction
和kCAMediaTimingFunctionLinear
代码如下所示:
CAMediaTimingFunction *linearTiming =
[CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear];
[CATransaction setAnimationTimingFunction: linearTiming]
答案 1 :(得分:0)
在Swift 4.2中,CATransaction
有一个名为setAnimationTimingFunction(_:)
的方法。 setAnimationTimingFunction(_:)
具有以下声明:
class func setAnimationTimingFunction(_ function: CAMediaTimingFunction?)
设置用于该交易组内所有动画的计时功能。 [...]这是一种方便的方法,可以将
CAMediaTimingFunction
键的value(forKey:)
值设置为kCATransactionAnimationTimingFunction
。
因此,您可以使用以下代码片段之一来为CATransaction
设置线性动画:
CATransaction.begin()
CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear))
/* ... */
CATransaction.commit()
CATransaction.begin()
CATransaction.setValue(CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear), forKey: kCATransactionAnimationTimingFunction)
/* ... */
CATransaction.commit()