无法将UIImageView放在SKScene的视图中

时间:2014-03-06 19:36:55

标签: ios iphone cocoa-touch uikit sprite-kit

我需要显示一个gif图像,我尝试了SKSpriteNote但它没有gif支持。所以我想改用UIImageView

在MyScene.m初始化方法中:

#import "UIImage+animatedGIF.h"

CGSize size = CGSizeMake(144, 82);

//create a uiview on top of skview
self.demoView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width / 2 - size.width / 2, self.view.bounds.size.height / 2 - size.height / 2, size.width, size.height)];

[self.view addSubview:self.demoView];

//set the image to be the gif (I use a category from github)
self.demoView.image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL URLWithString:[Helper pathInBundleWithFileName:[self demoFileNameWithStep:step]]]];
[self.demoView startAnimating];

这与gif图像无关,因为即使我尝试静态png图像,也不会显示图像视图。

我也试过这个,但它也没有用:

    [self.view.superview addSubview:self.demoView];
    [self.view.superview bringSubviewToFront:self.demoView];

1 个答案:

答案 0 :(得分:2)

将引用self.view的代码移至SKScene方法didMoveToView:。在此之前(即在init中),self.view引用将为零,因为尚未在视图上显示场景。