Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa 更改CALayer特性的动画时间_Cocoa_Core Animation_Quartz Graphics - Fatal编程技术网

Cocoa 更改CALayer特性的动画时间

Cocoa 更改CALayer特性的动画时间,cocoa,core-animation,quartz-graphics,Cocoa,Core Animation,Quartz Graphics,我有一个CALayer来设置图像内容变化的动画。现在,我怎样才能更改此动画发生所需的时间?这或多或少很简单。你有一个ivarCALayer*yourLayer。然后设置委托并实现委托方法-(id)actionForLayer:forKey: - (void)awakeFromNib { yourLayer.delegate = self; yourLayer.name = @"yourLayer"; } - (id <CAAction>)actionForLaye

我有一个CALayer来设置图像内容变化的动画。现在,我怎样才能更改此动画发生所需的时间?

这或多或少很简单。你有一个ivar
CALayer*yourLayer
。然后设置委托并实现委托方法
-(id)actionForLayer:forKey:

- (void)awakeFromNib {
    yourLayer.delegate = self;
    yourLayer.name = @"yourLayer";
}  
- (id <CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event {
    if([layer.name isEqualToString yourLayer.name]) { // Check for right layer

        CABasicAnimation *ani = [CABasicAnimation animationWithKeyPath:event]; // Default Animation for 'event'
        ani.duration = .5; // Your custom animation duration
        return ani;

    } else return nil; // Default Animation
}
-(void)从NIB唤醒{
yourLayer.delegate=self;
yourLayer.name=@“yourLayer”;
}  
-(id)actionForLayer:(CALayer*)层forKey:(NSString*)事件{
如果([layer.name IsequalString yourLayer.name]){//检查是否有正确的层
CABasicAnimation*ani=[CABasicAnimation animationWithKeyPath:event];//事件的默认动画
ani.duration=.5;//自定义动画的持续时间
返回ani;
}else返回nil;//默认动画
}

另一种方法:

[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:2.5f] forKey:kCATransactionAnimationDuration];
//Perform CALayer actions, such as changing the layer contents, position, whatever.
aCALayerObject.contents = [self newCALayerContents];    
[CATransaction commit];
该代码将在2.5秒内设置CALayer内容更改的动画。也可以使用此选项完全禁用所有动画。像这样:

[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
你可以打电话:

[CATransaction setAnimationDuration:durationSecs] 

在-LayoutSublayer中或修改层并希望其隐式动画的任何其他位置。这将影响当前隐式事务和其中的任何子事务。

从何处获取
CATransaction
对象?
CATransaction
是一个类
setAnimationDuration:seconds
是一个类方法。在本例中,它设置当前事务的持续时间。谢谢,我现在就知道了。