2,在APPDelegate.m中增加属性:@property (strong, nonatomic) UIView *launchView
3,在- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions;中调用下面方法
-(void)setLaunchImg{
UIViewController *viewController = [[UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil] instantiateViewControllerWithIdentifier:@"LaunchScreen"]
self.launchView= viewController.view
self.launchView.frame = CGRectMake(0, 0, self.window.screen.bounds.size.width, self.window.screen.bounds.size.height)
[self.window addSubview:self.launchView]
UIImageView*imageV = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,self.launchView.frame.size.width,self.launchView.frame.size.height)]
[imageVsetImage:[UIImageimageNamed:@"logo.jpeg"]]
imageV.contentMode = UIViewContentModeScaleAspectFill
[self.launchViewaddSubview:imageV]
[self.window bringSubviewToFront:self.launchView]
//可以设置启动页的存在时间
[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(removeLun) userInfo:nil repeats:NO]
}
-(void)removeLun
{
[self.launchView removeFromSuperview]
}
自从Xcode 12+开始,使用LaunchImage配置固定大小图片的方案已被苹果爸爸废弃,想要设置启动页需要通过LaunchScreen,个人理解苹果之所以作这样的改动是基于苹果新推出的全面屏和越来越多的屏幕尺寸以及Safe Area机制(这里要注意,Safe Area需要iOS 9+)
创建工程,随之会自动创建一个LaunchScreen.storyboard的文件
点击打开可以发现和传统的xib文件无差别
可以在这个storyboard上可以放置各种ImageView、Label等,但需要注意UI控件必须添加在Safe Area区域内,这样无论是iPhone X之后的刘海全面屏还是iPhone 8这样的非全面屏都可以正常显示,通过下方的View as:iPhone 11 可以选择各种不同的机型/横竖屏来查看当前启动页的展示情况
如果本文对你有所帮助记得点个赞哈 :)
两种方法设置:LaunchScreen.storyboard
在LaunchScreen.storyboard中拖拽imageView并设置约束,勾选右侧Use as launch Screen
工程—General—App Icons and Launch Images选项中设置Launch Screen File为所制作的LaunchScreen.storyboard或者LaunchScreen.xib
Assets.xcassets
设置LaunchImage
准备:
各种尺寸启动图:640 × 960,640 × 1136,750 × 1334,1242 × 2208,(横平需要2208 ×1242)
iPhone Portrait iOS5,6(1x:320 × 480 pixels, 2x:640 × 960 pixels, Retina 4:640 × 1136 pixels)
iPhone Portrait iOS8,9(Retina HD 5.5”:1242 × 2208 pixels, Retina HD 4.7”:750 × 1334 pixels)
iPhone Landscape iOS 8,9(Retina HD 5.5”:2208 × 1242 pixels)
iPhone Portrait iOS7,9(2x:640 × 960 pixels, Retina 4:640 × 1136 pixels)
iPhone X Portrait iOS 11+ (3x:1125 x 2436 pixels)
配置
工程—General—App Icons and Launch Images选项中设置Launch Image Source 为LaunchImage
LaunchScreen.storyboard 取消勾选Use as Launch Screen
置空路径Launch Screen File
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)