动画CALayer隐藏

时间:2010-07-15 22:40:32

标签: objective-c cocoa calayer cabasicanimation

我试图在几微秒后隐藏CALayer并且我正在使用CABasicAnimation为隐藏设置动画。

目前我正在尝试使用

[aLayer setHidden:YES];

CABasicAnimation * hideAnimation = [CABasicAnimation animationWithKeyPath:@"hidden"];
[hideAnimation setDuration:aDuration];
[hideAnimation setFromValue:[NSNumber numberWithBool:NO]];
[hideAnimation setToValue:[NSNumber numberWithBool:YES]];
[hideAnimation setBeginTime:0.09];
[hideAnimation setRemovedOnCompletion:NO];
[hideAnimation setDelegate:self];

[alayer addAnimation:hideAnimation forKey:@"hide"];

但是当我运行它时,图层会立即隐藏,而不是等待所需的beginTime。

我不确定我的keyPath是“隐藏”但找不到任何其他选项,文档确实声明hidden的{​​{1}}属性是可动画的。

实现我正在寻找的目标的正确方法是什么?

5 个答案:

答案 0 :(得分:3)

尝试设置不透明度属性的动画。从1.0到0.0,你应该得到你想要的效果。

答案 1 :(得分:3)

来自CAMediaTiming.h,它说的是关于beginTime属性:

  

对象的开始时间,在   与其父对象的关系,如果   适用。默认为0。

您应该使用CACurrentMediaTime()+所需的时间偏移。

[hideAnimation setBeginTime:CACurrentMediaTime() + 0.09];

答案 2 :(得分:3)

我确信这对于原版海报来说太晚了,但它可能对其他人有所帮助。我一直在尝试做类似的事情,除了在更改hidden属性时隐藏动画。正如Tom所说,动画opacity在这种情况下不起作用,因为对图层隐藏属性的更改似乎立即生效(即使我使用beginTime延迟动画)。

标准隐式动作使用淡入淡出过渡(CATransitiontype = kCATransitionFade),但这对整个图层起作用,我想同时执行另一个动画,这不是兼容的操作

经过多次实验,我终于注意到了上面@ Kevin的评论---你好! ---实际上有效!所以我只是想把它叫出来,这样解决方案对未来的搜索者来说更加明显:

CAKeyframeAnimation* hiddenAnim = [CAKeyframeAnimation animationWithKeyPath:@"hidden"];
hiddenAnim.values = @[@(NO),@(YES)];
hiddenAnim.keyTimes = @[@0.0, @1.0];
hiddenAnim.calculationMode = kCAAnimationDiscrete;
hiddenAnim.duration = duration;

这会将隐藏延迟到持续时间结束。将其与组中的其他属性动画组合以在图层消失之前看到它们的效果。 (您可以将其与不透明度动画结合使用,使图层淡出,同时执行另一个动画。)

谢谢你,凯文!

答案 3 :(得分:1)

swift 4

display: block

答案 4 :(得分:0)

import cv2
import subprocess as sp
import numpy

FFMPEG_BIN = "ffmpeg"
command = [ FFMPEG_BIN,
        '-i', 'fifo',             # fifo is the named pipe
        '-pix_fmt', 'bgr24',      # opencv requires bgr24 pixel format.
        '-vcodec', 'rawvideo',
        '-an','-sn',              # we want to disable audio processing (there is no audio)
        '-f', 'image2pipe', '-']    
pipe = sp.Popen(command, stdout = sp.PIPE, bufsize=10**8)

while True:
    # Capture frame-by-frame
    raw_image = pipe.stdout.read(640*480*3)
    # transform the byte read into a numpy array
    image =  numpy.fromstring(raw_image, dtype='uint8')
    image = image.reshape((480,640,3))          # Notice how height is specified first and then width
    if image is not None:
        cv2.imshow('Video', image)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    pipe.stdout.flush()

cv2.destroyAllWindows()
相关问题