Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使我的精灵套件场景显示在UIView上方?_Ios_Objective C_Uiview_Uiimageview_Sprite Kit - Fatal编程技术网

Ios 如何使我的精灵套件场景显示在UIView上方?

Ios 如何使我的精灵套件场景显示在UIView上方?,ios,objective-c,uiview,uiimageview,sprite-kit,Ios,Objective C,Uiview,Uiimageview,Sprite Kit,我做了一些搜索,但没有找到任何直接解决我的问题的方法:我有一个SKScene,其中有几个SKNodes节点,每个节点都有SKSpriteNode对象用于我的游戏,我使用的是背景UIImageView(至少据我所知,我需要在背景中做一些事情,而这些事情在精灵套件中是不合理的);我遇到的问题是,UIImageView出现在所有东西之上,我看不到我的游戏对象 在我的视图控制器(.m文件)中,我有以下代码来调用我的场景 @implementation GameViewController - (voi

我做了一些搜索,但没有找到任何直接解决我的问题的方法:我有一个
SKScene
,其中有几个
SKNodes
节点,每个节点都有
SKSpriteNode
对象用于我的游戏,我使用的是背景
UIImageView
(至少据我所知,我需要在背景中做一些事情,而这些事情在精灵套件中是不合理的);我遇到的问题是,
UIImageView
出现在所有东西之上,我看不到我的游戏对象

在我的视图控制器(.m文件)中,我有以下代码来调用我的场景

@implementation GameViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    SKView * skView = (SKView *)self.view;

     SKScene * scene = [GameScene sceneWithSize:skView.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;
    [skView presentScene:scene];

}
在上面的
游戏场景
中,我有几个
SKNodes
,其中我的所有游戏对象都是的子对象(例如
nodeHDU
nodePlay
nodePause菜单
),我使用
UIImageView
作为背景(随着时间的推移,我在背景场景之间切换,并且使用了一些很好的过渡,例如
uiviewmanimationoptiontransitioncrosssolve;
如果不使用多个
SKSpriteNode
和复杂的
SKActions
数组作为背景,就无法实现这一点“m使用
UIImageView

然而,在Xcode中运行应用程序时,我只看到上面的
ImageBackground
。我游戏中的其他对象(其他节点的子对象)存在,各种
NSLog
语句被调用,但它们似乎出现在我拥有的
ImageBackground
后面。上面的代码“belowSubview”和“sendSubviewToBack”没有帮助


因此,我如何将
imageBackground
发送为实际背景?

您的问题在于,您直接将
SKView
设置为控制器视图。要解决此问题,请不要将
self.view
设置为
SKView
的一种类型。在故事板或Xib中执行以下步骤:

  • 首先在控制器的视图上添加一个
    UIImageView
    。同时设置图像
  • 然后在
    UIImageView
    上添加
    SKView
    ,并将
    UIClearColor
    设置为背景色
  • 因此,完整的层次结构类似于
    UIViewController
    ->
    UIView
    ->
    UIImageView
    ->
    SKView

    UIView *backgrounds = [[UIView alloc] init];
    [self.view insertSubview:backgrounds belowSubview:self.view];
    
    UIImageView *imageBackground = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
    [backgrounds addSubview:imageBackground];
    [backgrounds sendSubviewToBack:imageBackground];
    [imageBackground setImage:[UIImage imageNamed:@"1-A.png"]];
    imageBackground.alpha=1.0;