2016-03-01 56 views
0

我试图用一种又一种的动画书风格动画一系列图像。当我在Apple TV模拟器上运行下面的代码时,我看到一个空白的白色透明屏幕,它是默认的。主视图和我的图像视图似乎消失了。任何建议为什么请?Apple TV上的CAKeyframeAnimation没有显示

- (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"]; 
} 

回答

0

问题是CAKeyframeAnimation只接受CGImages,不UIImages默默失败。需要将CGImages添加到阵列并投射如下:

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