Programing

React Native의 iOS 시작 화면

crosscheck 2020. 8. 24. 07:34
반응형

React Native의 iOS 시작 화면


React Native 앱으로 작업 중이며 사용자 지정 시작 화면을 설정하려고하는데 할 수 없습니다.

React Native는 기본적으로 LaunchScreen.xib를 생성하므로 Images.xcassets 내에 LaunchImage를 생성했습니다.

Images.xcassets의 LaunchImage

또한 내 옵션의 "앱 아이콘 및 실행 이미지"에서 "실행 화면 파일"을 수정해야한다고 읽었습니다.

이미지 옵션 시작

이 작업을 마치면 시작 화면이 완전히 검게 변하고 앱이로드되면 상단 및 하단 검은 색 프레임이 모두 나타납니다.

여기에 이미지 설명 입력

그래서 React Native 프로젝트에서 시작 화면을 설정하기 위해 무엇을해야하는지 모르겠습니다.

누군가가 그러한 문제를 도와 줄 수 있으면 감사하겠습니다.

미리 감사드립니다.


이 스레드의 도움으로 문제를 해결할 수있었습니다 : Launch Image가 iOS 애플리케이션에 표시되지 않음 (Images.xcassets 사용)

그래서 다른 사람에게 도움이 될 수 있도록 깊이 설명하겠습니다.

먼저 특정 이미지를 만들어야합니다. 제가 사용한 것은이 템플릿과 자동 생성기가있는이 웹 페이지 였습니다 . TiCons

여기에 이미지 설명 입력

내 이미지를 다운로드 할 때 assets / iphone 폴더에있는 이미지를 가져 왔고 다음 이미지 만 가져 왔습니다.

  • Default@2x.png (640x960)
  • Default-568h@2x.png (640x1136)
  • Default-667h@2x.png (750x1334)
  • Default-Portrait-736h@3x.png (1242x2208)
  • Default-Landscape-736h@3x.png (2208x1242)

또한 같은 폴더 에이 Contents.json 파일 이 필요합니다 . 친구에게서 받았습니다.

{
  "images": [
    {
      "extent": "full-screen",
      "idiom": "iphone",
      "filename": "Default-568h@2x.png",
      "minimum-system-version": "7.0",
      "orientation": "portrait",
      "scale": "2x",
      "subtype": "retina4"
    },
    {
      "extent": "full-screen",
      "idiom": "iphone",
      "filename": "Default-667h@2x.png",
      "minimum-system-version": "8.0",
      "orientation": "portrait",
      "scale": "2x",
      "subtype": "667h"
    },
    {
      "extent": "full-screen",
      "idiom": "iphone",
      "filename": "Default-Landscape-736h@3x.png",
      "minimum-system-version": "8.0",
      "orientation": "landscape",
      "scale": "3x",
      "subtype": "736h"
    },
    {
      "extent": "full-screen",
      "idiom": "iphone",
      "filename": "Default-Portrait-736h@3x.png",
      "minimum-system-version": "8.0",
      "orientation": "portrait",
      "scale": "3x",
      "subtype": "736h"
    },
    {
      "extent": "full-screen",
      "idiom": "iphone",
      "filename": "Default@2x.png",
      "minimum-system-version": "7.0",
      "orientation": "portrait",
      "scale": "2x"
    }
  ],
  "info": {
    "version": 1,
    "author": "xcode"
  }
}

그래서,이 시점에서 나는라는 폴더 생성 LaunchImage.launchimage를 내부 Images.xcassets 내 반작용 기본 프로젝트와 이미지 저장 폴더 Contents.json의 그 안에 파일 :

여기에 이미지 설명 입력

Second, you have to open your project in Xcode and in "General" settings, below "App icons and Launch Images" we have to leave the option "Launch Screen File" empty (also we can delete the LaunchScreen.xib file inside our project), and click in "Use Asset Catalog" after that. A modal will open, we choose to Migrate the catalog Images

여기에 이미지 설명 입력

Now, in the "Launch Images Source" selector, we can choose the folder we created before, LaunchImage (the one with our images):

여기에 이미지 설명 입력

We pick this instead of Brand Assets and we can delete Brand Assets folder.

At this point, we'll be able to run our React Native application with our custom launch images:

여기에 이미지 설명 입력

I know it seems a little bit complex for an supposedly easy task, but after reading a lot about it this was the only way I could get my splash images working, so I wanted to share with the community.


Make sure to delete the app from the simulator. Then do a clean on your project.


I recommend generator-rn-toolbox for applying launch screen or main icon using on react-native. It is more simple and easy to use through cli as react-native.

  • Do not need to open XCode.
  • Do not need to make a lot of image files for various resolutions.
  • Anytime change launch screen using one line commend.

Requirements

  • node >= 6
  • One square image or psd file with a size of more than 2208x2208 px resolution for a launch screen(splash screen)
  • Positive mind ;)

Install

  1. Install generator-rn-toolbox and yo
  2. npm install -g yo generator-rn-toolbox
  3. Install imagemagick brew install imagemagick
  4. Apply splash screen on iOS

    yo rn-toolbox:assets --splash YOURIMAGE.png --ios

    or Android

    yo rn-toolbox:assets --splash YOURIMAGE.png --android

That's all. :)

Source


I have been looking at these answers a lot in SO containing solutions for how to create a new launch screen. I mean let's think about it for a minute.

When we create a new react-native project what do we see for the launch screen?

> Facebook's default launch screen

So that got me thinking, How did they do it?

They created a LaunchScreen.xib

I think there must be a reason for this. So I went into theLaunchScreen.xib and made a change to the default text "React Native..." or what ever it said. I ran the app one more time to see that the launch screen reflected my edits.

Solution 1 Edit the existing LaunchScreen.xib

Solution 2 Create my own

So I did, it took me longer to type up this answer than learning how to create my own. Both of these solutions are compatible with all the devices.

Step 1:

Delete LaunchScreen.xib

step 2:

click on images.xcassets right click in the white space click **import**then select the image you want to add. 여기에 이미지 설명 입력

step 3:

Right click on your project's root folder and add a new file of type Launch Screen and name it what ever you want.

여기에 이미지 설명 입력

step 4

Click on your project in the left nav, go to Settings > General and under App Icons and Launch Images. Make sure Launch Image Source is blank and the Launch Screen File is the same name as your newly created launch screen.

여기에 이미지 설명 입력

step 5

Click on your brand new file you created in step 2, drag an Image View or edit how ever it pleases you.

여기에 이미지 설명 입력

Then that's it, you're done. You don't even need to clean the solution, just rebuild.


Just went through this and works a treat. The only road block I discovered was not clearing the simulator content. If you find that your new launch screen isn't working you need to open the simulation and go to the following:

Simulator > Reset content and settings

There must be some hardcore caching going on within that simulator but once that was done - rerun and you'll see the app. Make sure you do this for both xcode simulators and react-native simulators!


Make sure the 'Launch Screen File' select is empty: 여기에 이미지 설명 입력


Follow this link:

If you want to add a splash screen to my React Native application.Follow the process, the result will be all yours.

STEP:1 First,I created a splashImageResource folder and added the launchScreen.xib file with the splash image.

STEP:2 change the code as written inside the subviews tag. with this code<subviews> <imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" image="splash.png" translatesAutoresizingMaskIntoConstraints="NO" id="ZkI-RL-69Z"> </imageView> </subviews>

STEP:3 You should open your app in Xcode. Here are the steps to follow:

a) Go to your project folder

b) Open the ios folder

c) Go to the file that has .xcodeproj as the extension, in my case it's splasScreenTutorial.xcodeproj

d) Open this file in your Xcode.

e) Delete the launchScreen.xib file.

f) Click on the splashScreenTutorial folder, then go to the TARGETS section

g) Click on the General Tab on the top-left corner of your Xcode and scroll down to App Icons and Launch Images

h) Go to Launch Images Source and click Use Asset Catalog. Click on migrate.

i) Remove the text LaunchScreen from Launch Screen File.

j) Go back to your project folder and open the Images.xcassets file. You should see AppIcon and LaunchImage.

k) Next, click on the LaunchImage, Finally, drag the splash screen images that you have of different sizes to the Launch Image box.

Drag the images like this.

Test Splash Screen a) To see the changes, you need to delete the app from your simulator if you have run the app initially.

b) To delete the app, click on the Hardware menu on your Simulator bar and go to Home.

c) Tap and hold down the particular app icon you want to delete, and click on the X sign on the icon.

d) Run your app again using react-native run-ios

You can see your Splash Screen


If you want to use the existing Launch Screen .xib file React Native initially has set up, but with your own logo and background color (and without any of the React Native default text), you can follow the instructions here: https://medium.com/@kelleyannerose/react-native-ios-splash-screen-in-xcode-bd53b84430ec.


If you create a Launch screen with the help of React then you should add the same thing in the LaunchScreen.xib file in iOS Xcode for that you can take a Screenshot and add it as an Image in the Images.xcassets.

Open LaunchScreen then add UIImageView in the View from Object Library from Right Panel in Xcode.

여기에 이미지 설명 입력

Add Trailing, Leading, Bottom and Top Constraints to the View. As Shown Below -

여기에 이미지 설명 입력

Don't Forget to change the UIImageView ContentMode as AspectFit so that it will look same when the app runs.

After That you need to add code in AppDelegate so that you don't get a white screen. The code is -

 UIView* launchScreenView = [[[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil] objectAtIndex:0];
 launchScreenView.frame = self.window.bounds;
 rootView.loadingView = launchScreenView;

You can Refer - https://facebook.github.io/react-native/docs/running-on-device.html#pro-tip


Just for those still having trouble, there is one more step missing from the accepted answer before making the iOS Launch screen work.

Open Info.plist in the project folder and delete "Main nib file base name" key. Then, rebuild and hopefully the issue is gone.


For me on XCode 10.1 and react-native 59.2 I had to go through the additional steps after already adding the images, storyboard and 1 universal image.

  • Right click on the image, click Show in Finder, then edit your Contents.json file
  • Add the image to the 2x and 3x sections
  • Go to the Launch Screen storyboard, with the "ruler" menu
  • Make sure only the inside red arrows are on, not the outside red arrows
  • Click "Safe Area Relative Margins"

여기에 이미지 설명 입력

Image should now be centered on all size iPhones (tested on Portrait).


Upon following the above solutions my app was getting stuck on the Splash Screen so I did the following 7 steps to add the custom splash screen on ios.

  1. Open the Xcode and locate the LaunchScreen.xib file in your project (Notice that this is the screen which is shown by default in ios)
  2. To remove/edit the text on the screen click on it and do the necessary changes as you like.
  3. To change the background color locate the following icons on the right side bar and click the little icon button at the very top, fourth from the left (when you hover, it’ll say “Show the Attributes Inspector”)

여기에 이미지 설명 입력

  1. Now that you have know how to change the background color, lets add image to the Splash screen to do that click on the following button and select the Image view from the list and drag and place it where ever you want it on the splash screen.

여기에 이미지 설명 입력

  1. Now we have to add the image to the Images.xcassets so that we can reference it in the LaunchScreen.xib to do that goto Images.xcassets. click on + button followed by import and then add the image you want to show in the splash screen. Beneath AppIcon you’ll see your image file name. This is the name we’ll use to reference in our LaunchScreen.xib

  2. Now we have to reference the image we added in the LaunchScreen.xib file so navigate back to LaunchScreen.xib and click the image view that we added earlier and on the right hand corner you will see bunch of options. click on first one that says image and select the image which you imported in step 5

여기에 이미지 설명 입력

  1. clean the project and run react-native run-ios and you should see the changes.

시작 화면 이미지 소스를 이미지 세트로 설정해야합니다. 나중에 LauncScreen.xib 파일을 삭제하십시오. 나중에 프로젝트에서 전역 검색을 수행하고 LaunchScreen.xib에 대한 모든 참조를 제거합니다 (전체 프로젝트를 살펴 봅니다. 저는 숭고한 텍스트 편집기를 사용하므로 cmd + shift + f입니다).

참고 URL : https://stackoverflow.com/questions/34027270/ios-launch-screen-in-react-native

반응형