I need to show a gif image and I have tried SKSpriteNote but it has no gif support. So I want to use UIImageView instead.

in MyScene.m init method:

#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];

It's not about the gif image, because even if I try static png image, the image view is not shown.

I have tried this as well but it's not working either:

    [self.view.superview addSubview:self.demoView];
    [self.view.superview bringSubviewToFront:self.demoView];
有帮助吗?

解决方案

Move code that refers to self.view to the SKScene method didMoveToView:. Before that (ie in init) the self.view reference will be nil because the scene hasn't been presented on a view yet.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top