简体   繁体   English

故事板上可见的Xcode图像不会在模拟器中显示

[英]Xcode images visible in storyboard don't show in simulator

I'm new to xcode. 我是xcode的新手。 I created a spritekit game with a single view controller and storyboard. 我用一个视图控制器和情节提要创建了一个spritekit游戏。 After completing the game I wanted to create a new scene with image button that would open the game view. 完成游戏后,我想创建一个带有图像按钮的新场景,以打开游戏视图。

In main.storyboard i have added a new UIViewController from the object library. 在main.storyboard中,我从对象库中添加了一个新的UIViewController。 I set view controller as the initial view controller. 我将视图控制器设置为初始视图控制器。 I added a button, control dragged from the button to the other view and set the action to show. 我添加了一个按钮,将控件从该按钮拖动到另一个视图,并将动作设置为显示。 When running the simulator everything worked as planned. 运行模拟器时,所有操作均按计划进行。 I then tried to add an image to the button. 然后,我尝试将图像添加到按钮。 The image shows on the view in the editor window but will not show in the simulator when set either as image or background. 图像显示在编辑器窗口的视图中,但是当设置为图像或背景时将不会显示在模拟器中。 I then drug an image directly onto the new view controller. 然后,我将图像直接添加到新的视图控制器中。 It shows in the editor as well but not in the simulator. 它也显示在编辑器中,但不显示在模拟器中。 I've tried using multiple different images including those that are used in the game and show on both the simulator and on a device in the game. 我尝试使用多种不同的图像,包括游戏中使用的图像,并在模拟器和游戏中的设备上显示。 I've tried multiple simulators with no luck. 我尝试了多个模拟器,但没有运气。 When adding the image to the button I can tell the button is not off the simulator screen because when I click the spot where the button should be it opens the other view just as it should. 当将图像添加到按钮时,我可以知道按钮不在模拟器屏幕之外,因为当我单击按钮应位于的位置时,它将按原样打开另一个视图。 I've cleaned and rebuilt the project, made sure all images are in the correct folder and properly named. 我清理并重建了项目,确保所有图像都位于正确的文件夹中并正确命名。

It turned to be a noob issue. 原来这是一个菜鸟问题。

All of my images were in a folder called sprites.atlas. 我所有的图像都放在一个名为sprites.atlas的文件夹中。 This worked fine for my SKView but didn't work for my new UIView. 这对我的SKView来说效果很好,但对我的新UIView却不起作用。

To solve the problem I: 为了解决这个问题,我:

**1. ** 1。 Added a new image set to Images.xcassets 在Images.xcassets中添加了一个新图像集

  1. Added my button images to the new image set 将我的按钮图像添加到新图像集中

  2. Changed the button image property to point to the image set name** 更改了按钮图像属性以指向图像集名称**

The button images now show in the sim. 现在,按钮图像显示在sim卡中。

For future users, this worked for me : 对于将来的用户,这对我有用:

1) Clean the project 1)清理项目

2) Restart Xcode 2)重新启动Xcode

3) Run 3)运行

PS If you face some new issues like random crashing then enable ARC and then keep buiding <--> fixing on a copy and then check. PS:如果您遇到一些新问题,例如随机崩溃,请启用ARC,然后继续对副本进行buiding <--> fixing ,然后进行检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM