一个显示启动图如“知乎日报”的视图控制器。
pod 'KCLaunchImage'
添加到您的 Podfile
中。pod install
。KCLaunchImageViewController.h
和 KCLaunchImageViewController.m
添加到您的项目(如果您从 pod 中安装,请跳过此步骤)。Images.xcassets
下创建一个名为 FakeLaunchImage
的新文件夹。创建 4 种类型的图像集
FakeLaunchImage-320w-480h@2x
(iPhone4)FakeLaunchImage-320w-568h@2x
(iPhone5)FakeLaunchImage-375w-667h@2x
(iPhone6)FakeLaunchImage-414w-736h@3x
(iPhone6P)为每个图像集添加一个特定图像
将您自己的启动图添加到 LaunchImage
。
displayImage
的自定义显示图像(与 FakeLaunchImage
相同)。AppDelegate.m
文件中,添加以下代码。\#import "KCLaunchImageViewController.h"
\#import "UIImage+ForiPhone.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIImageView *splashScreen = [[UIImageView alloc] initWithImage:[UIImage autoSelectImageWithImageName:@"FakeLaunchImage"]];
[self.window addSubview:splashScreen];
self.window.rootViewController =
[KCLaunchImageViewController addTransitionToViewController:[[KCViewController alloc] init]
modalTransitionStyle:UIModalTransitionStyleCrossDissolve
withImageName:@"DisplayImage"
taskBlock:^(void){
[splashScreen removeFromSuperview];
}];
return YES;
}
文件应在 Sketch 中打开
如果你的图像在 images.xcassets
中,请设置 Deployment Target
>= 7.0。
kavichen,[email protected]
KCLaunchImage 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。