Skip to content

Commit 633a7cb

Browse files
committed
启动动画 - 策略改动:数据当次请求,当次展示。。
1 parent a3bd0fd commit 633a7cb

File tree

6 files changed

+56
-42
lines changed

6 files changed

+56
-42
lines changed

Coding_iOS/AppDelegate.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
9898
[self.window makeKeyAndVisible];
9999
[FunctionIntroManager showIntroPage];
100100

101-
EaseStartView *startView = [EaseStartView startView];
101+
EaseStartView *startView = [EaseStartView new];
102102
@weakify(self);
103103
[startView startAnimationWithCompletionBlock:^(EaseStartView *easeStartView) {
104104
@strongify(self);

Coding_iOS/Controllers/RootControllers/Project_RootViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ - (void)viewDidLoad{
143143
}
144144
[self setupNavBtn];
145145
self.icarouselScrollEnabled = NO;
146-
[[StartImagesManager shareManager] handleStartLink];//如果 start_image 有对应的 link 的话,需要进入到相应的 web 页面
146+
// [[StartImagesManager shareManager] handleStartLink];//如果 start_image 有对应的 link 的话,需要进入到相应的 web 页面
147147
// [self setupTerminalButton];
148148
}
149149

Coding_iOS/Util/Manager/StartImagesManager.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
- (void)handleStartLink;
2020

2121
- (void)refreshImagesPlist;
22+
- (void)refreshImagesBlock:(void(^)(NSArray<StartImage *> *images, NSError *error))bk;
23+
2224
- (void)startDownloadImages;
2325

2426
@end
@@ -37,4 +39,4 @@
3739

3840
@interface Group : NSObject
3941
@property (strong, nonatomic) NSString *name, *author, *link;
40-
@end
42+
@end

Coding_iOS/Util/Manager/StartImagesManager.m

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,24 +144,29 @@ - (void)loadStartImages{
144144
}
145145

146146
- (void)refreshImagesPlist{
147+
[self refreshImagesBlock:nil];
148+
}
149+
150+
- (void)refreshImagesBlock:(void(^)(NSArray<StartImage *> *images, NSError *error))bk{
147151
NSString *aPath = @"api/wallpaper/wallpapers";
148152
NSDictionary *params = @{@"type" : @"3"};
149-
[[CodingNetAPIClient sharedJsonClient] GET:aPath parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
150-
DebugLog(@"\n===========response===========\n%@:\n%@", aPath, responseObject);
151-
id error = [self handleResponse:responseObject];
153+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:aPath withParams:params withMethodType:Get autoShowError:NO andBlock:^(id data, NSError *error) {
154+
NSArray *resultA = nil;
152155
if (!error) {
153-
NSArray *resultA = [responseObject valueForKey:@"data"];
156+
resultA = data[@"data"];
154157
if ([self createFolder:[self downloadPath]]) {
155158
if ([resultA writeToFile:[self pathOfSTPlist] atomically:YES]) {
156159
[[StartImagesManager shareManager] startDownloadImages];
157160
}
158161
}
159162
}
160-
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
161-
DebugLog(@"\n===========response===========\n%@:\n%@", aPath, error);
163+
if (bk) {
164+
bk([NSObject arrayFromJSON:resultA ofObjects:@"StartImage"], error);
165+
}
162166
}];
163167
}
164168

169+
165170
- (void)startDownloadImages{
166171

167172
if (![AFNetworkReachabilityManager sharedManager].reachableViaWiFi) {

Coding_iOS/Views/EaseStartView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#import <UIKit/UIKit.h>
1010

1111
@interface EaseStartView : UIView
12-
+ (instancetype)startView;
1312

1413
- (void)startAnimationWithCompletionBlock:(void(^)(EaseStartView *easeStartView))completionHandler;
14+
1515
@end

Coding_iOS/Views/EaseStartView.m

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ @interface EaseStartView ()
1919

2020
@implementation EaseStartView
2121

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];
2924
if (self) {
25+
self.frame = kScreen_Bounds;
3026
//add custom code
3127
UIColor *bgColor = [UIColor whiteColor];
3228
self.backgroundColor = bgColor;
@@ -36,7 +32,7 @@ - (instancetype)initWithStartImage:(StartImage *)st{
3632
_bgImageView.alpha = 0.0;
3733
_bgImageView.contentMode = UIViewContentModeScaleAspectFill;
3834
[self addSubview:_bgImageView];
39-
35+
4036
_logoIconView = [[UIImageView alloc] init];
4137
_logoIconView.contentMode = UIViewContentModeScaleAspectFill;
4238
_logoIconView.image = [UIImage imageNamed:@"logo_coding"];
@@ -52,53 +48,64 @@ - (instancetype)initWithStartImage:(StartImage *)st{
5248
[_bgImageView bk_whenTapped:^{
5349
[weakSelf bgImageViewTapped];
5450
}];
55-
56-
self.st = st;
5751
}
5852
return self;
5953
}
6054

6155
- (void)setSt:(StartImage *)st{
6256
_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);
6659
}
6760

6861
- (void)bgImageViewTapped{
6962
if ([BaseViewController presentingVC].navigationController.viewControllers.count <= 1) {
7063
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];
7666
}
7767
}
7868

7969
- (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+
8079
[kKeyWindow addSubview:self];
8180
[kKeyWindow bringSubviewToFront:self];
8281
_bgImageView.alpha = 0.0;
83-
84-
@weakify(self);
82+
8583
[UIView animateWithDuration:1.0 animations:^{
86-
@strongify(self);
87-
self.bgImageView.alpha = 1.0;
84+
weakSelf.bgImageView.alpha = 1.0;
8885
} 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;
9389
} completion:^(BOOL finished) {
94-
@strongify(self);
95-
[self removeFromSuperview];
96-
if (completionHandler) {
97-
completionHandler(self);
98-
}
90+
[weakSelf p_animationCompletedWithBlock:completionHandler];
9991
}];
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+
}
101101
}];
102102
}
103103

104+
- (void)p_animationCompletedWithBlock:(void(^)(EaseStartView *easeStartView))completionHandler{
105+
[self removeFromSuperview];
106+
if (completionHandler) {
107+
completionHandler(self);
108+
}
109+
}
110+
104111
@end

0 commit comments

Comments
 (0)