Apple TV 上的 CAKeyframeAnimation 未显示

CAKeyframeAnimation on Apple TV not showing

我正在尝试一个接一个地制作动画书风格的一系列图像。当我在 Apple TV 模拟器上 运行 下面的代码时,我看到一个空白的白色透明屏幕,这是默认设置。主视图和我的图像视图似乎消失了。有什么建议吗?

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.view.backgroundColor = [UIColor blackColor];
    self.imageview1 =[[UIImageView alloc] initWithFrame:CGRectMake(0,0,480,1080)];
    self.imageview1.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.imageview1];
    self.array1 = [NSMutableArray array];

    for(int i = 0; i <10; i++)
    {
        NSString *imageName = [NSString stringWithFormat:@"loop_00_%d",i];
        //NSLog(imageName);
        NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:@"jpg"];
        UIImage *image = [UIImage imageWithContentsOfFile:path];
        [self.array1 addObject:image];
    }

    [self animateImages];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)animateImages
{
    CAKeyframeAnimation *keyframeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
    keyframeAnimation.values = self.array1;  // array with images

    keyframeAnimation.repeatCount = 1.0f;
    keyframeAnimation.duration = 10.0;

    keyframeAnimation.removedOnCompletion = YES;

    CALayer *layer = self.imageview1.layer;

    [layer addAnimation:keyframeAnimation
                 forKey:@"flingAnimation"];
}

问题是 CAKeyframeAnimation 只接受 CGImages,不接受 UIImages 并且静默失败。需要将 CGImages 添加到数组并按如下方式转换:

UIImage *image = [UIImage imageWithContentsOfFile:path];
[self.array1 addObject:(id)image.CGImage];