xcode 图像并非全部显示在模拟器上,而是显示在故事板中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14401900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:33:18  来源:igfitidea点击:

Images not all showing up on simulator but shows in storyboard

xcodeuiviewcontrolleruiimageviewstoryboard

提问by PressRay

I am pretty new to iOS development and I was poking around in storyboard in Xcode 4.5.2. I started a new tab bar project (5 tabs) and then dropped in some images (UIImageViews objects) to them, everything looked good and the build came out fine on the simulator but not all the images are showing up. The same image would be showing on the Firstviewcontroller but it won't show on another viewcontroller. And I can't seem to add new image objects into the firstone (meaning i can place it in the storyboard but new ones won't show up on the simulator), It almost seems to be showing cached screens. For example, I just randomly place images all over a viewcontroller and then shifted them around and ran the simulator again but the positions do not match.

我是 iOS 开发的新手,我在 Xcode 4.5.2 的故事板中闲逛。我开始了一个新的标签栏项目(5 个标签),然后将一些图像(UIImageViews 对象)放入其中,一切看起来都不错,并且在模拟器上构建效果很好,但并非所有图像都显示出来。相同的图像将显示在 Firstviewcontroller 上,但不会显示在另一个 viewcontroller 上。而且我似乎无法将新的图像对象添加到第一个(这意味着我可以将它放在情节提要中,但新的图像对象不会出现在模拟器上),它几乎似乎在显示缓存屏幕。例如,我只是在视图控制器上随机放置图像,然后将它们移动并再次运行模拟器,但位置不匹配。

Does anyone have any information or experience with this on Storyboard?

有没有人在 Storyboard 上有任何信息或经验?

Thanks in advance. Ray

提前致谢。射线

回答by Manab Kumar Mal

In my case when I have created new project in Xcode 6I can not show the images in the Simulator and as well as in device. I have imported all the images in the image assets making a folder within that.Now I have imported all the images, all are working fine now. All images are now showing now.

在我的情况下,当我在中创建新项目时,Xcode 6我无法在模拟器和设备中显示图像。我已经导入了图像资产中的所有图像,并在其中创建了一个文件夹。现在我已经导入了所有图像,现在一切正常。现在显示所有图像。

Follow these steps:

按着这些次序:

STEP 1:

第1步:

Step 1:

第1步:

STEP 2:

第2步:

Step 2

第2步

STEP 3:

第 3 步:

Step 3

第 3 步

and then Import images which you need. Reference Link: StackOverflow link

然后导入您需要的图像。参考链接: StackOverflow 链接

回答by Esteve

In my case the picture was a JPG and not a PNG. Replacing image in xcasset for the same image converted to PNG was the trick.

就我而言,图片是 JPG 而不是 PNG。将 xcasset 中的图像替换为转换为 PNG 的相同图像是诀窍。

回答by Vishal

I had a similar issue. But later found out that this was because I had put the images in a real folder in the app directory. So there was my project's folder, which contained another folder named 'Assets' which contained the images. This was solved when I moved my images out of the folder and put them in the project's root folder.

我有一个类似的问题。但是后来发现这是因为我把图片放在了app目录下的真实文件夹中。所以有我的项目文件夹,其中包含另一个名为“资产”的文件夹,其中包含图像。当我将图像移出文件夹并将它们放在项目的根文件夹中时,这个问题得到了解决。

回答by Waleed Abdalmajeed

Restarting simulator fixed my problem. I think it was a cache problem.

重新启动模拟器解决了我的问题。我认为这是一个缓存问题。

NOTE:I'm using iOS 10 with xcode 8

注意:我使用的是 iOS 10 和 xcode 8

回答by A. F. Al-khateeb

I encountered this problem after I refactored storyboard. The possible solution: - Go to Storyboard and select the image you don't see in the simulator. - Go to the Attributes inspector and re-select the image again.

我在重构storyboard后遇到了这个问题。可能的解决方案: - 转到 Storyboard 并选择您在模拟器中看不到的图像。- 转到属性检查器并再次重新选择图像。

After Storyboard refactor, sometimes Xcode assigns Unknown imageto the UIImageView.

在 Storyboard 重构之后,有时 Xcode 会分配Unknown image给 UIImageView。

Reselecting the image solved the problem.

重新选择图像解决了问题。

回答by Douglas

@PressRay, I have been toying around with things and have some suggestions. I have moved this to an answer, because they would have put us in chat if we kept going. But hopefully this will do it. First off, I think you should make your tab bar from interface builder, perhaps you have input some code incorrectly. You can either start one from the first screen of create a new project, or you can drag one in from the library. But it is a Tab Bar controller. Then for each of your five views, you can place a view controller on the screen for it. Then you can drag from your tab bar controller to each of the five new view controllers and select relationship tab bar controller. This will set up each vc for you.

@PressRay,我一直在玩弄东西并有一些建议。我已将其移至答案,因为如果我们继续前进,他们会让我们聊天。但希望这能做到。首先,我认为您应该从界面构建器中制作标签栏,也许您输入了错误的代码。您可以从创建新项目的第一个屏幕开始,也可以从库中拖入一个。但它是一个标签栏控制器。然后对于您的五个视图中的每一个,您都可以在屏幕上为其放置一个视图控制器。然后你可以从你的标签栏控制器拖动到五个新的视图控制器中的每一个,然后选择关系标签栏控制器。这将为您设置每个 vc。

Next I would suggest you turn off auto layout to get a feel for story boards first before you jump into auto layout and constraints. That is why I think your png's are not showing up. The two lines look like they are too close together because of some contraint moving them. To do this select the view controller, make sure it is just the view controller and then in the right hand view, go to the file inspector, it looks like a page icon. Under Interface Builder Document should be a check box for Use Autolayout. Click this so there is no check mark. Now you will be using struts and spring on each vc that you turn this off. So go ahead and turn it off on all of them.

接下来,我建议您在进入自动布局和约束之前先关闭自动布局以感受故事板。这就是为什么我认为您的 png 没有出现的原因。由于某些限制移动它们,这两条线看起来靠得太近了。为此选择视图控制器,确保它只是视图控制器,然后在右侧视图中,转到文件检查器,它看起来像一个页面图标。在 Interface Builder Document 下应该是 Use Autolayout 的复选框。单击此按钮,因此没有复选标记。现在,您将在关闭此功能的每个 vc 上使用 struts 和 spring。因此,请继续将其全部关闭。

Next you have some png files to put in. Drag your image views to wherever you want them in any of your vc's. Then hook up the png files by selecting the image view and then once again on the right hand view select the attributes inspector and under the drop down menu of Image find the png that you want. Then you can move the image views anywhere in the vc that you want. I think this will solve your problem. Let me know what happens or if you have any questions.

接下来,您需要放入一些 png 文件。将您的图像视图拖动到任何 vc 中您想要的任何位置。然后通过选择图像视图连接 png 文件,然后再次在右侧视图中选择属性检查器,并在图像的下拉菜单下找到您想要的 png。然后您可以将图像视图移动到您想要的 vc 中的任何位置。我认为这将解决您的问题。如果您有任何疑问,请告诉我会发生什么。

回答by Sherry

For xcode beta (swift 4) converted the jpg to a png file, and created a folder called images.xcassets, added the png file to the folder. It worked going to try adding the jpeg to the folder and see if the image shows up. I just tried the jpeg and its not showing up. So my conclusion is to use png files and create a folder to hold the png files. Add the folder right after the Main.storyboard. Hope this helps.

对于 xcode beta (swift 4) 将 jpg 转换为 png 文件,并创建一个名为 images.xcassets 的文件夹,将 png 文件添加到该文件夹​​中。尝试将 jpeg 添加到文件夹中并查看图像是否显示出来。我刚刚尝试了 jpeg,但它没有出现。所以我的结论是使用 png 文件并创建一个文件夹来保存 png 文件。在 Main.storyboard 之后添加文件夹。希望这可以帮助。

回答by Naveed Abbas

It happens when you change the folder for your storyboard or image. (Possibly copied storyboard from another project).

当您更改故事板或图像的文件夹时会发生这种情况。(可能是从另一个项目复制的故事板)。

Find your Image in the Project Navigator, Select it and change it's location to (Relative to Project)

在项目导航器中找到您的图像,选择它并将其位置更改为(相对于项目)

enter image description here

在此处输入图片说明

If necessary, you'd need to relink your image.

如有必要,您需要重新链接您的图像。

回答by wandhi Zakari

try to check the image properties in your project in case you haven't set them not yet set

如果您没有设置它们,请尝试检查项目中的图像属性 还没有设置

to

after set

设置后