Get the LaunchImage of the app

Get the LaunchImage of the app

[[153741]]

The management of LaunchImage is actually quite simple in iOS, especially after Xcode introduced xcassets, it is a completely fool-proof operation. But sometimes we still need to do something with LaunchImage.

LaunchImage will disappear immediately after the APP is initialized and the APP interface will be displayed. But sometimes we don’t want it to disappear so quickly (for example, some people want a transition effect, while others want it to disappear after certain settings or data are loaded). This is also very simple. We just need to display LaunchImage again and pin it to the top.

For example,

However, we have configured so many LaunchImages for different screen resolutions. How do we get the LaunchImage that is suitable for the current screen resolution?

The common way is to add all LaunchImage to the project and name them according to the screen resolution, such as (640_960.png 640_1136.png ...) and then use code to splice the corresponding file name in the program and reference it.

However, this method is relatively primitive and if Apple releases some devices with other resolutions in the future or the startup image changes, it will need to be manually modified. The project configuration is not good and it will take up more resources (the capacity of the APP will increase again).

Cherpak Evgeny on stackflow shared a better way to directly read the settings in NSBundle to get the currently applicable LaunchImage

I wrote a demonstration code based on the above picture as an example

  1. CGSize viewSize = self.window.bounds.size;
  2. NSString *viewOrientation = @ "Portrait" ; //For horizontal screen, please set it to @"Landscape"  
  3. NSString *launchImage = nil;
  4. NSArray* imagesDict = [[[NSBundle mainBundle] infoDictionary] valueForKey:@ "UILaunchImages" ];
  5. for (NSDictionary* dict in imagesDict)
  6. {
  7. CGSize imageSize = CGSizeFromString(dict[@ "UILaunchImageSize" ]);
  8.       
  9. if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@ "UILaunchImageOrientation" ]])
  10. {
  11. launchImage = dict[@ "UILaunchImageName" ];
  12. }
  13. }
  14. UIImageView *launchView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:launchImage]];
  15. launchView.frame = self.window.bounds;
  16. launchView.contentMode = UIViewContentModeScaleAspectFill;
  17. [self.window addSubview:launchView];
  18. [UIView animateWithDuration: 2 .0f
  19. delay : 0.0f
  20. options:UIViewAnimationOptionBeginFromCurrentState
  21. animations:^{
  22.                        
  23. launchView.alpha = 0 .0f;
  24. launchView.layer.transform = CATransform3DScale(CATransform3DIdentity, 1.2 , 1.2 , 1 );
  25.                        
  26. }
  27. completion:^(BOOL finished) {
  28.                        
  29. [launchView removeFromSuperview];
  30.                        
  31. }];

This way you can easily get LaunchImage~

<<:  Who helped Apple come back to life 20 years ago? It was Microsoft!

>>:  iOS 9.2 beta arrives with new features that may focus on stylus

Recommend

What would you see if you dismantled 300 nuclear power plants?

2022 The world's first artificial nuclear rea...

The eighth course of the Xiaomao Qianqian Writing Training Camp

The course comes from the eighth session of Xiaom...

213,900-329,900! The first choice for elite families, Haobo HT high-gloss launch

As elite families continue to grow and develop, t...

How much more would it cost to return iPhone production to the U.S.?

Not long ago, the newly elected President of the ...

APP user growth: One model solves 90% of growth problems!

If growth cannot be achieved, it is most likely n...

Tik Tok live streaming skills for the jewelry industry

"Jewelry is silent, but it can move women mo...

How to create efficient and high-quality ground promotion?

2014 was a boom year for mobile healthcare. Accor...

How to Become a Great JavaScript Programmer

[[138028]] When I was a teenager, my interests sp...

Can a personal public account open a mini program?

Q: How can I activate a mini program on my person...

If you want to lose 10 pounds before summer, start eating like this now!

As the temperature rises day by day, everyone'...