Get the LaunchImage and iosapplaunchimage of the App in iOS
Author: This site is authorized to repost the record.
LaunchImage management is actually relatively simple in iOS, especially after Xcode introduces xcassets, it is completely silly. However, sometimes we still need to write articles on the Launch Image.
LaunchImage will disappear immediately after APP initialization and display the APP interface, but sometimes we don't want it to disappear so quickly (for example, some people want a transitional effect, others want to wait for some settings) or disappear after the data is loaded) this is also very simple. We only need to display the LaunchImage and set it to the top.
For example
However, we have configured so many launchimages for different screen resolutions. How can we obtain the LaunchImage suitable for the current screen resolution?
The general method is to add all launchimages to the project and name them according to the screen resolution, for example, (640_960.png 640_1136.png ...) In the program, splice the corresponding file name with the code and reference it.
However, this method is relatively primitive. In the future, if Apple has other resolution devices or the startup diagram changes, it will require manual modification of the engineering configuration. In addition, it will take up more resources. (The APP capacity has increased)
Cherpak Evgeny on stackflow shares a better way to directly read the settings in NSBundle to obtain the currently applicable LaunchImage.
The above figure is used as an example to write a Demo code.
CGSize viewSize = self. window. bounds. size; NSString * viewOrientation = @ "Portrait"; // set the Landscape to @ "Landscape" NSString * launchImage = nil; NSArray * imagesDict = [[NSBundle mainBundle] infoDictionary] valueForKey: @ "UILaunchImages"]; for (NSDictionary * dict in imagesDict) {CGSize imageSize = CGSizeFromString (dict [@ "UILaunchImageSize"]); if (CGSizeEqualToSize (imageSize, viewSize) & [viewOrientation is1_tostring: dict [@ "login"]) {launchImage = dict [@ "UILaunchImageName"] ;}} UIImageView * launchView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: launchImage]; launchView. frame = self. window. bounds; launchView. contentMode = UIViewContentModeScaleAspectFill; [self. window addSubview: launchView]; [UIView animateWithDuration: 2.0f delay: 0.0f options: UIViewAnimationOptionBeginFromCurrentState animations: ^ {launchView. alpha = 0.0f; launchView. layer. transform = CATransform3DScale (CATransform3DIdentity, 1.2, 1.2, 1);} completion: ^ (BOOL finished) {[launchView removeFromSuperview];}];
This makes LaunchImage easy.