Get the LaunchImage and iosapplaunchimage of the App in iOS

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.