XCode中有LaunchScreen.storyboard或者LaunchScreen.xib疾忍,蘋果默認(rèn)使用的就是拿這個(gè)當(dāng)啟動(dòng)頁(yè),這是一個(gè)靜態(tài)的頁(yè)面企孩,也就是只能用自動(dòng)布局來(lái)適配屏幕的大小,就一張圖片居中顯示袁稽,這個(gè)兼容性不強(qiáng)勿璃。另外一種方法,這種方法很多人都在用推汽,只要設(shè)置正確 尺寸格式正確就可以正常顯示的补疑。常用的尺寸格式如下:
CA87F4BA-7F54-486B-9E8D-6B5AB1190D26.png
B1A951D8-A8A2-43AB-B8F0-2EC86F61DCEA.png
步驟如下:
1、點(diǎn)擊Image.xcassets 進(jìn)入圖片管理,然后右擊,彈出"New Launch Image"
2歹撒、如圖,右側(cè)的勾選可以讓你選擇是否要對(duì)ipad,橫屏,豎屏,以及低版本的ios系統(tǒng)做支持.這邊我選了ios8.0,ios7.0,ios6沒(méi)有做支持.
55A47D57-7A6A-4DBD-91AD-B89C63CB2A8A.png
3莲组、選擇launchImage
975202FB-6791-4DD8-B1B0-521401F43097.png
4、清空Launch Screen File
72CB1773-D0F9-4466-814D-91DC7FA24454.png
5暖夭、加入版本號(hào)的代碼
#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[ViewController alloc] init];
[self.window makeKeyAndVisible];
[self customLaunchImageView];
return YES;
}
- (void)customLaunchImageView
{
UIImageView *launchImageView = [[UIImageView alloc] initWithFrame:self.window.bounds];
launchImageView.image = [self getLaunchImage];
[self.window addSubview:launchImageView];
[self.window bringSubviewToFront:launchImageView];
UILabel *vesionLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 260, 100, 30)];
vesionLabel.backgroundColor = [UIColor cyanColor];
//獲取當(dāng)前設(shè)備中應(yīng)用的版本號(hào)
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
vesionLabel.text = [NSString stringWithFormat:@"V %@",currentVersion];
vesionLabel.textAlignment = NSTextAlignmentCenter;
[launchImageView addSubview:vesionLabel];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[UIView animateWithDuration:1.2 animations:^{
launchImageView.alpha = 0.0;
launchImageView.transform = CGAffineTransformMakeScale(1.2, 1.2);
} completion:^(BOOL finished) {
[launchImageView removeFromSuperview];
}];
});
}
- (UIImage *)getLaunchImage
{
UIImage *lauchImage = nil;
NSString *viewOrientation = nil;
CGSize viewSize = [UIScreen mainScreen].bounds.size;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
viewOrientation = @"Landscape";
} else {
viewOrientation = @"Portrait";
}
NSArray *imagesDictionary = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
for (NSDictionary *dict in imagesDictionary) {
CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]);
if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]]) {
lauchImage = [UIImage imageNamed:dict[@"UILaunchImageName"]];
}
}
return lauchImage;
}
運(yùn)行結(jié)果:
3B27A049-EA3F-4F0E-A78D-B066EB5FDD9F.png