简体   繁体   English

启动带有居中图像 iOS 的屏幕情节提要

[英]Launch Screen Storyboard with centered image iOS

1 - I want to use a LaunchScreen.storyboard in my app 1 - 我想在我的应用程序中使用 LaunchScreen.storyboard

2 - In this launch screen I need to insert a brand image in center of the screen 2 - 在此启动屏幕中,我需要在屏幕中央插入品牌形象

Could anyone help me?有人可以帮助我吗?

The answer by @Jhonsore did not work for me, unfortunately.不幸的是,@Jhonsore 的答案对我不起作用。

Here's what I did to get it working:这是我为使其正常工作所做的工作:

!Note This also works for .xib files, which comes with React Native init !注意这也适用于 React Native init 附带的 .xib 文件

Adding the image file添加图像文件

1) Under image.xcassets, right click and choose New Image Set . 1)在 image.xcassets 下,右键单击并选择New Image Set Create three different sizes of your image (@1x, @2x, @3x) and add the images by dragging them into the slots for 1x, 2x, 3x.创建三种不同尺寸的图像(@1x、@2x、@3x)并通过将图像拖入 1x、2x、3x 的插槽来添加图像。 For 3x I suggest a size of more than 1200 px.对于 3x,我建议大小超过 1200 像素。

新图像集

2) Name the new image set something, for intance: splash 2)命名新图像集的东西,例如:飞溅

Creating the launch screen创建启动屏幕

1) Right-click your project, click New File... , and add a Launch Screen. 1)右键单击您的项目,单击New File... ,然后添加一个 Launch Screen。

2) Select your project and under General->App icons and launch images->Launch Screen File select your newly created Launch Screen 2)选择您的项目,然后在General->App 图标和启动图像->Launch Screen File 下选择您新创建的 Launch Screen

启动屏幕文件

3) Open the launch screen 3)打开启动画面

4) Select View Controller Scene->View Controller 4)选择视图控制器场景->视图控制器

启动 Screen.storyboard

5) In the right panel choose Simulated Metrics->Size and change it to Page Sheet 5)在右侧面板中选择Simulated Metrics->Size并将其更改为Page Sheet

选择页表

6) In the left panel delete the two text inputs (copyright and project name) 6)在左侧面板中删除两个文本输入(版权和项目名称)

7) Add an Image View by clicking the button shown in the screenshot below and dragging it to the center of the view 7)通过单击下面屏幕截图中显示的按钮并将其拖动到视图的中心来添加图像视图

添加图像视图

8) In the right panel with Image View selected choose View->Content Mode->Aspect Fit . 8)在选择 Image View 的右侧面板中,选择View->Content Mode->Aspect Fit Also add your image by choosing **Image View->Image还可以通过选择 **Image View->Image 添加您的图像

在此处输入图片说明

10) Go to Size Inspector (ruler icon, see screenshot) and choose a width and a height that looks good (this will scale to other screen sizes). 10)转到尺寸检查器(标尺图标,见截图)并选择一个看起来不错的宽度和高度(这将缩放到其他屏幕尺寸)。

在此处输入图片说明

11) Drag your image into the center of the screen until you see both a horizontal and vertical blue line 11)将图像拖到屏幕中央,直到看到水平和垂直的蓝线

12) Lastly, under Autoresizing change the window with the arrows, so it looks like in the screenshot above. 12)最后,在Autoresizing下用箭头更改窗口,所以它看起来像上面的屏幕截图。 All outer arrows should be deselected and all inner arrows selected.应取消选择所有外部箭头并选择所有内部箭头。

Result结果

iphone xs 最大 在此处输入图片说明

Troubleshooting: If your images are not showing on the simulator, try restarting it or try select another device.故障排除:如果您的图像未显示在模拟器上,请尝试重新启动它或尝试选择其他设备。

Bus image Credits: Eliott Van Buggenhout巴士图片来源: Eliott Van Buggenhout

I got it!我明白了!

Here is a link with the steps images: 这是包含步骤图像的链接:

1 - Set launch file in tab > General 1 - 在选项卡 > 常规中设置启动文件

2 - Select LaunchScreen.storyboard in Project navigator, check the option "Use as Launch Screen" in file Inspector 2 - 在项目导航器中选择 LaunchScreen.storyboard,在文件检查器中选中“用作启动屏幕”选项

3 - Drag and drop an ImageView inside the Views Controller Scene 3 - 在视图控制器场景中拖放一个 ImageView

4 - Select the ImageView added before, change its width and height. 4 - 选择之前添加的 ImageView,更改其宽度和高度。 I put wxh 200我把 wxh 200

First, check the box and after change the size value首先,选中该框,然后更改大小值

Click "Add 2 constraints" button单击“添加 2 个约束”按钮

5 - With ImageView selected, change position to centralize it. 5 - 选择 ImageView 后,更改位置以将其居中。

First, check the box and after change the size value首先,选中该框,然后更改大小值

Click "Add 2 constraints" button单击“添加 2 个约束”按钮

6 - It is almost done!!! 6 - 快完成了!!!

Now let's resolve Auto Layout Issues, click the button "Resolve Auto Layout Issues" and update frames现在让我们解决自动布局问题,单击“解决自动布局问题”按钮并更新框架

7 - It's time to pick out our image 7 - 是时候挑选我们的形象了

With ImageView selected go to > Atributes Inspector tab and choose the image u want, remenber to remove its extension (it is the trick, because the image may note appear when building the app on real device, happened with me!!!).选择 ImageView 后,转到 > Atributes Inspector 选项卡并选择您想要的图像,记住删除其扩展名(这是诀窍,因为在真实设备上构建应用程序时可能会注意到图像,发生在我身上!!!)。

8 - So, CMD+R to build and run your app. 8 - 所以,CMD+R 来构建和运行你的应用程序。 Voilá!!!!!瞧!!!!

I solved it with responsive settings我用响应式设置解决了它

In Attribute Inspector -> Content Mode -> Aspect Fill在 Attribute Inspector -> Content Mode -> Aspect Fill

在此处输入图片说明

in Size Inspector -> Layout -> Automatice:在尺寸检查器 -> 布局 -> 自动:

在此处输入图片说明

Add new constraint -> fill like the image below and click Add 5 constraints添加新约束 -> 如下图所示填充,然后单击添加 5 个约束

在此处输入图片说明

The only workaround that works for me was to add the images outside Images.xcassets folder.唯一对我Images.xcassets解决方法是在Images.xcassets文件夹外添加图像。 After I modified this and rebuilt the app, it worked as expected.在我修改并重建应用程序后,它按预期工作。

The same issue is happening on the iOS 14 or XCode 12 .同样的问题发生在iOS 14XCode 12

从Images.xcassets中将图片移出到文件外面,可以重新构建应用即可。这个为题chu

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

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