启动带有居中图像 iOS 的屏幕情节提要
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37951817/
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
Launch Screen Storyboard with centered image iOS
提问by Jhonsore
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?
有人可以帮助我吗?
回答by Jhonsore
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. I put w x h 200
4 - 选择之前添加的 ImageView,更改其宽度和高度。我把 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. Voilá!!!!!
8 - 所以,CMD+R 来构建和运行你的应用程序。瞧!!!!
回答by Attaque
The answer by @Jhonsore did not work for me, unfortunately.
不幸的是,@Jhonsore 的答案对我不起作用。
Here's what I did to get it working:
这是我为使其工作所做的工作:
!NoteThis 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. Create three different sizes of your image (@1x, @2x, @3x) and add the images by dragging them into the slots for 1x, 2x, 3x. For 3x I suggest a size of more than 1200 px.
1)在 image.xcassets 下,右键单击并选择New Image Set。创建三种不同尺寸的图像(@1x、@2x、@3x)并通过将图像拖入 1x、2x、3x 的插槽来添加图像。对于 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 Fileselect 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)选择视图控制器场景->视图控制器
5)In the right panel choose Simulated Metrics->Sizeand 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 Viewby clicking the button shown in the screenshot below and draggingit to the center of the view
7)通过单击下面屏幕截图中显示的按钮并将其拖动到视图的中心来添加图像视图
8)In the right panel with Image View selected choose View->Content Mode->Aspect Fit. Also add your image by choosing **Image View->Image
8)在选择 Image View 的右侧面板中,选择View->Content Mode->Aspect Fit。还可以通过选择 **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 Autoresizingchange the window with the arrows, so it looks like in the screenshot above. All outer arrows should be deselected and all inner arrows selected.
12)最后,在Autoresizing下用箭头更改窗口,所以它看起来像上面的屏幕截图。应取消选择所有外部箭头并选择所有内部箭头。
Result
结果
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
回答by Idan
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 个约束