@@ -19,14 +19,10 @@ @interface EaseStartView ()
19
19
20
20
@implementation EaseStartView
21
21
22
- + (instancetype )startView {
23
- StartImage *st = [[StartImagesManager shareManager ] randomImage ];
24
- return [[self alloc ] initWithStartImage: st];
25
- }
26
-
27
- - (instancetype )initWithStartImage : (StartImage *)st {
28
- self = [super initWithFrame: kScreen_Bounds ];
22
+ - (instancetype )init {
23
+ self = [super init ];
29
24
if (self) {
25
+ self.frame = kScreen_Bounds ;
30
26
// add custom code
31
27
UIColor *bgColor = [UIColor whiteColor ];
32
28
self.backgroundColor = bgColor;
@@ -36,7 +32,7 @@ - (instancetype)initWithStartImage:(StartImage *)st{
36
32
_bgImageView.alpha = 0.0 ;
37
33
_bgImageView.contentMode = UIViewContentModeScaleAspectFill;
38
34
[self addSubview: _bgImageView];
39
-
35
+
40
36
_logoIconView = [[UIImageView alloc ] init ];
41
37
_logoIconView.contentMode = UIViewContentModeScaleAspectFill;
42
38
_logoIconView.image = [UIImage imageNamed: @" logo_coding" ];
@@ -52,53 +48,64 @@ - (instancetype)initWithStartImage:(StartImage *)st{
52
48
[_bgImageView bk_whenTapped: ^{
53
49
[weakSelf bgImageViewTapped ];
54
50
}];
55
-
56
- self.st = st;
57
51
}
58
52
return self;
59
53
}
60
54
61
55
- (void )setSt : (StartImage *)st {
62
56
_st = st;
63
- UIImage *bgImage = [st.image scaleToSize: [_bgImageView doubleSizeOfFrame ] usingMode: NYXResizeModeAspectFill];
64
- self.bgImageView .image = bgImage;
65
- // [self.bgImageView sd_setImageWithURL:[NSURL URLWithString:self.st.url]];
57
+ [self .bgImageView sd_setImageWithURL: [NSURL URLWithString: self .st.url]];
58
+ DebugLog (@" setSt : ---- %@ " , st.url );
66
59
}
67
60
68
61
- (void )bgImageViewTapped {
69
62
if ([BaseViewController presentingVC ].navigationController .viewControllers .count <= 1 ) {
70
63
NSString *linkStr = self.st .group .link ;
71
- if ([linkStr hasPrefix: [NSObject baseURLStr ]]) {
72
- // [BaseViewController presentLinkStr:linkStr];
73
- UIViewController *vc = [BaseViewController analyseVCFromLinkStr: linkStr] ?: [WebViewController webVCWithUrlStr: linkStr];
74
- [BaseViewController goToVC: vc];
75
- }
64
+ UIViewController *vc = [BaseViewController analyseVCFromLinkStr: linkStr] ?: [WebViewController webVCWithUrlStr: linkStr];
65
+ [BaseViewController goToVC: vc];
76
66
}
77
67
}
78
68
79
69
- (void )startAnimationWithCompletionBlock : (void (^)(EaseStartView *easeStartView))completionHandler {
70
+ __weak typeof (self) weakSelf = self;
71
+ // 加载数据 st
72
+ [[StartImagesManager shareManager ] refreshImagesBlock: ^(NSArray <StartImage *> *images, NSError *error) {
73
+ if (images.count > 0 ) {
74
+ NSInteger index = arc4random () % images.count ;
75
+ weakSelf.st = images[index];
76
+ }
77
+ }];
78
+
80
79
[kKeyWindow addSubview: self ];
81
80
[kKeyWindow bringSubviewToFront: self ];
82
81
_bgImageView.alpha = 0.0 ;
83
-
84
- @weakify (self);
82
+
85
83
[UIView animateWithDuration: 1.0 animations: ^{
86
- @strongify (self);
87
- self.bgImageView .alpha = 1.0 ;
84
+ weakSelf.bgImageView .alpha = 1.0 ;
88
85
} completion: ^(BOOL finished) {
89
- dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t )(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue (), ^{
90
- [UIView animateWithDuration: 0.6 delay: .0 options: UIViewAnimationOptionCurveEaseIn animations: ^{
91
- @strongify (self);
92
- [self setX: -kScreen_Width ];
86
+ if (!weakSelf.st ) {// 此时若 st 还未加载到,则省去展示停顿时间
87
+ [UIView animateWithDuration: .3 delay: .0 options: UIViewAnimationOptionCurveEaseIn animations: ^{
88
+ weakSelf.alpha = .0 ;
93
89
} completion: ^(BOOL finished) {
94
- @strongify (self);
95
- [self removeFromSuperview ];
96
- if (completionHandler) {
97
- completionHandler (self);
98
- }
90
+ [weakSelf p_animationCompletedWithBlock: completionHandler];
99
91
}];
100
- });
92
+ }else {// 若 st 数据已加载,停留展示,然后消失
93
+ dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t )(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue (), ^{
94
+ [UIView animateWithDuration: 0.6 delay: .0 options: UIViewAnimationOptionCurveEaseIn animations: ^{
95
+ weakSelf.x = -kScreen_Width ;
96
+ } completion: ^(BOOL finished) {
97
+ [weakSelf p_animationCompletedWithBlock: completionHandler];
98
+ }];
99
+ });
100
+ }
101
101
}];
102
102
}
103
103
104
+ - (void )p_animationCompletedWithBlock : (void (^)(EaseStartView *easeStartView))completionHandler {
105
+ [self removeFromSuperview ];
106
+ if (completionHandler) {
107
+ completionHandler (self);
108
+ }
109
+ }
110
+
104
111
@end
0 commit comments