代码之家  ›  专栏  ›  技术社区  ›  OMGPOP

无法将UIImageView放入SKScene的视图中

  •  1
  • OMGPOP  · 技术社区  · 12 年前

    我需要显示gif图像,我已尝试 SKSpriteNote 但它不支持gif。所以我想用 UIImageView 相反

    在MyScene.m init方法中:

    #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 回复  |  直到 12 年前
        1
  •  2
  •   CodeSmile Paul Beusterien    12 年前

    移动引用的代码 self.view 到SKScene方法 didMoveToView: .在此之前(即在init中) 自我.view 引用将为零,因为场景尚未呈现在视图中。