启动时闪屏的组成
- Luanch Screen + Splash Screen
1. Luanch Screen 启动屏(系统级)
- 在 Main 函数之前 + didFinshLaunch 前
- 系统启动 App 自动展示
- 在准备好 App UI 数据后自动消失
如何设置系统启动页?
1-1. 在Assets.xcassets 中右键创建,创建名为LuanchImage的文件
1 2
1-2. 在工程 Build Settings 搜索 Asset Catalog Launch Image Set Name ,然后把值设置为新建的图片名字即可
image.png1-3. 在项目 Info.plist 删除 Launch screen interface file base name 并添加 LaunchImage 并设置 LaunchImage
image.png2. Splash Screen 闪屏(业务逻辑)
- Launch Screen 展示时间短,不能看清
- 实现同样的图片,显示图标等信息
- 实现广告/推广活动页面
如何添加?
在 window 添加一层 View
AppDelegate -》 didFinishLaunchingWithOptions()
// 添加
[self.window addSubview:({
GTSplashView *splashView = [[GTSplashView alloc] initWithFrame:self.window.bounds];
splashView;
})];
// GTSplashView 类
#import "GTSplashView.h"
#import "GTScreen.h"
@interface GTSplashView ()
@property(nonatomic,strong,readwrite)UIButton *button;
@property(nonatomic,strong,readwrite)UIImageView *imageView;
@end
@implementation GTSplashView
-(instancetype) initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
self.backgroundColor = [UIColor whiteColor];
self.image = [UIImage imageNamed:@"icon.bundle/remmber_water2.png"];
[self addSubview:({
// _imageView = [UIImage imageNamed:@"icon.bundle/splash_tip.png"];
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(UI(30), frame.size.height/2-UI(50)/2, frame.size.width-UI(60),UI(50))];
[_imageView setImage:[UIImage imageNamed:@"icon.bundle/splash_tip.png"]];
_imageView;
})];
[self addSubview:({
_button = [[UIButton alloc] initWithFrame:UIRect(330,100,60,40)];
_button.backgroundColor = [UIColor lightGrayColor];
[_button setTitle:@"跳过" forState:UIControlStateNormal];
[_button addTarget:self action:@selector(_removeSplashView) forControlEvents:UIControlEventTouchUpInside];
_button;
})];
self.userInteractionEnabled = YES;
}
return self;
}
-(void)_removeSplashView{
[self removeFromSuperview];
}
@end
更多详细的代码
github
网友评论