gpt4 book ai didi

ios - 无法将 UIImageView 放入 SKScene 的 View 中

转载 作者:行者123 更新时间:2023-11-29 10:46:22 24 4
gpt4 key购买 nike

我需要显示一个 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 图像,也不会显示 ImageView 。

我也试过了,但还是不行:

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

最佳答案

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

关于ios - 无法将 UIImageView 放入 SKScene 的 View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22234257/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com