-
Notifications
You must be signed in to change notification settings - Fork 16
/
LaunchScreenViewController.m
79 lines (63 loc) · 2.33 KB
/
LaunchScreenViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// LaunchScreenViewController.m
// LaunchScreenViewController
//
// Created by Anton Bukov on 19.11.14.
// Copyright (c) 2014 Anton Bukov. All rights reserved.
//
#import "LaunchScreenViewController.h"
@interface LaunchScreenViewController ()
@property (nonatomic, strong) UIView *snapshotView;
@property (nonatomic, readonly) NSString *launchScreenName;
@property (nonatomic, readonly) BOOL isStatusBarInitiallyHidden;
@end
@implementation LaunchScreenViewController
- (UIView *)snapshotView
{
if (_snapshotView == nil) {
UIView *viewCopy = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:self.view]];
UIWindow *window = [UIApplication sharedApplication].keyWindow;
[window addSubview:viewCopy];
viewCopy.frame = window.bounds;
UIGraphicsBeginImageContextWithOptions([UIScreen mainScreen].bounds.size, YES, 0.0);
[viewCopy.layer renderInContext:UIGraphicsGetCurrentContext()];
[viewCopy removeFromSuperview];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
_snapshotView = [[UIImageView alloc] initWithImage:img];
_snapshotView.frame = [UIScreen mainScreen].bounds;
}
return _snapshotView;
}
- (NSString *)launchScreenName
{
return [[NSBundle mainBundle] infoDictionary][@"UILaunchStoryboardName"];
}
- (BOOL)isStatusBarInitiallyHidden
{
return [[[NSBundle mainBundle] infoDictionary][@"UIStatusBarHidden"] boolValue];
}
- (BOOL)prefersStatusBarHidden
{
return self.isStatusBarInitiallyHidden;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIApplication *app = [UIApplication sharedApplication];
self.view = [[UINib nibWithNibName:self.launchScreenName bundle:nil] instantiateWithOwner:self options:nil].firstObject;
self.view.frame = app.keyWindow.bounds;
[self.view layoutIfNeeded];
if (self.isStatusBarInitiallyHidden)
app.keyWindow.windowLevel = UIWindowLevelStatusBar+1;
[app.keyWindow addSubview:self.snapshotView];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.snapshotView removeFromSuperview];
UIApplication *app = [UIApplication sharedApplication];
if (self.isStatusBarInitiallyHidden)
app.keyWindow.windowLevel = UIWindowLevelNormal;
}
@end