7
7
//
8
8
9
9
#define kIntroPageKey @" intro_page_version"
10
- #define kIntroPageNum 2
10
+ #define kIntroPageNum 4
11
11
12
12
#import " FunctionIntroManager.h"
13
13
#import " EAIntroView.h"
14
14
#import " SMPageControl.h"
15
15
#import < NYXImagesKit/NYXImagesKit.h>
16
16
17
+ @interface FunctionIntroManager ()
18
+ @property (strong , nonatomic ) EAIntroView *introView;
19
+ @end
17
20
18
21
@implementation FunctionIntroManager
19
22
#pragma mark EAIntroPage
20
-
21
23
+ (void )showIntroPage {
22
- if (![self needToShowIntro ]) {
23
- return ;
24
- }
25
- NSMutableArray *pages = [NSMutableArray new ];
26
- for (int index = 0 ; index < kIntroPageNum ; index ++) {
27
- EAIntroPage *page = [self p_pageWithIndex: index];
28
- [pages addObject: page];
29
- }
30
- if (pages.count <= 0 ) {
31
- return ;
32
- }
33
- EAIntroView *introView = [[EAIntroView alloc ] initWithFrame: kScreen_Bounds andPages: pages];
34
- introView.backgroundColor = [UIColor whiteColor ];
35
- introView.swipeToExit = YES ;
36
- introView.scrollView .bounces = YES ;
37
-
38
- // introView.skipButton = [self p_skipButton];
39
- // introView.skipButtonY = 20.f + CGRectGetHeight(introView.skipButton.frame);
40
- // introView.skipButtonAlignment = EAViewAlignmentCenter;
41
-
42
- if (pages.count <= 1 ) {
43
- introView.pageControl .hidden = YES ;
44
- }else {
45
- introView.pageControl = [self p_pageControl ];
46
- introView.pageControlY = 10 .f + CGRectGetHeight (introView.pageControl .frame );
24
+ if ([self needToShowIntro ]) {
25
+ FunctionIntroManager *manager = [FunctionIntroManager shareManager ];
26
+ [manager.introView showFullscreen ];
27
+ [self markHasBeenShowed ];
47
28
}
48
- [introView showFullscreen ];
49
- //
50
- [self markHasBeenShowed ];
51
29
}
52
30
53
31
+ (BOOL )needToShowIntro {
54
- // return YES;
55
-
56
32
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults ];
57
33
NSString *preVersion = [defaults stringForKey: kIntroPageKey ];
58
- BOOL needToShow = ![preVersion isEqualToString: kVersion_Coding ];
59
- if (![NSDate isDuringMidAutumn ]) {// 中秋节期间才显示
60
- needToShow = NO ;
61
- }
34
+ BOOL needToShow = ![preVersion isEqualToString: kVersionBuild_Coding ];
62
35
return needToShow;
63
36
}
64
37
65
38
+ (void )markHasBeenShowed {
66
39
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults ];
67
- [defaults setValue: kVersion_Coding forKey: kIntroPageKey ];
40
+ [defaults setValue: kVersionBuild_Coding forKey: kIntroPageKey ];
68
41
[defaults synchronize ];
69
42
}
70
43
71
44
#pragma mark private M
72
- + (UIPageControl *)p_pageControl {
45
+
46
+ + (instancetype )shareManager {
47
+ static FunctionIntroManager *shared_manager = nil ;
48
+ static dispatch_once_t pred;
49
+ dispatch_once (&pred, ^{
50
+ shared_manager = [self new ];
51
+ });
52
+ return shared_manager;
53
+ }
54
+
55
+ - (instancetype )init
56
+ {
57
+ self = [super init ];
58
+ if (self) {
59
+ NSMutableArray *pages = [NSMutableArray new ];
60
+ for (int index = 0 ; index < kIntroPageNum ; index ++) {
61
+ EAIntroPage *page = [self p_pageWithIndex: index];
62
+ [pages addObject: page];
63
+ }
64
+ _introView = [[EAIntroView alloc ] initWithFrame: kScreen_Bounds andPages: pages];
65
+ _introView.backgroundColor = [UIColor whiteColor ];
66
+ _introView.swipeToExit = YES ;
67
+ _introView.scrollView .bounces = YES ;
68
+ _introView.skipButton = nil ;
69
+ if (pages.count <= 1 ) {
70
+ _introView.pageControl .hidden = YES ;
71
+ }else {
72
+ _introView.pageControl = [self p_pageControl ];
73
+ _introView.pageControlY = 10 .f + CGRectGetHeight (_introView.pageControl .frame );
74
+ }
75
+ }
76
+ return self;
77
+ }
78
+
79
+ - (UIPageControl *)p_pageControl {
73
80
UIImage *pageIndicatorImage = [UIImage imageNamed: @" intro_dot_unselected" ];
74
81
UIImage *currentPageIndicatorImage = [UIImage imageNamed: @" intro_dot_selected" ];
75
82
@@ -87,36 +94,63 @@ + (UIPageControl *)p_pageControl{
87
94
return (UIPageControl *)pageControl;
88
95
}
89
96
90
- + (UIButton *)p_skipButton {
91
- UIButton *button = [[UIButton alloc ] initWithFrame: CGRectMake (0 , 0 , kScreen_Width *0.7 , 60 )];
92
- button.titleLabel .font = [UIFont boldSystemFontOfSize: 18 ];
97
+ - (UIButton *)p_skipButton {
98
+ UIButton *button = [UIButton new ];
99
+ [button addTarget: self action: @selector (dismissIntroView ) forControlEvents: UIControlEventTouchUpInside];
100
+ button.titleLabel .font = [UIFont boldSystemFontOfSize: 14 ];
101
+ button.backgroundColor = kColorNavBG ;
102
+ [button setTitleColor: kColor999 forState: UIControlStateNormal];
103
+ [button setTitleColor: kColorDDD forState: UIControlStateHighlighted];
104
+ [button setTitle: @" 跳过" forState: UIControlStateNormal];
105
+ [button doBorderWidth: 0 color: nil cornerRadius: 15.0 ];
106
+ return button;
107
+ }
108
+
109
+ - (UIButton *)p_useImmediatelyButton {
110
+ UIButton *button = [UIButton new ];
111
+ [button addTarget: self action: @selector (dismissIntroView ) forControlEvents: UIControlEventTouchUpInside];
112
+ button.titleLabel .font = [UIFont boldSystemFontOfSize: 20 ];
113
+ button.backgroundColor = kColorBrandGreen ;
114
+ [button setTitleColor: [UIColor whiteColor ] forState: UIControlStateNormal];
115
+ [button setTitleColor: [UIColor lightTextColor ] forState: UIControlStateHighlighted];
93
116
[button setTitle: @" 立即体验" forState: UIControlStateNormal];
94
- [button setTitleColor: kColorBrandGreen forState: UIControlStateNormal];
95
- [button setTitleColor: [UIColor colorWithHexString: @" 0x1b9d59" ] forState: UIControlStateHighlighted];
117
+ [button doBorderWidth: 0 color: nil cornerRadius: 4.0 ];
96
118
return button;
97
119
}
98
120
99
- + (EAIntroPage *)p_pageWithIndex : (NSInteger )index {
121
+ - (void )dismissIntroView {
122
+ [self .introView hideWithFadeOutDuration: 0.3 ];
123
+ }
124
+
125
+ - (EAIntroPage *)p_pageWithIndex : (NSInteger )index {
100
126
NSString *imageName = [NSString stringWithFormat: @" intro_page%ld " , (long )index];
101
- if (kDevice_Is_iPhone6Plus ) {
102
- imageName = [imageName stringByAppendingString: @" _ip6+" ];
103
- }else if (kDevice_Is_iPhone6 ){
104
- imageName = [imageName stringByAppendingString: @" _ip6" ];
105
- }else if (kDevice_Is_iPhone5 ){
106
- imageName = [imageName stringByAppendingString: @" _ip5" ];
107
- }else {
108
- imageName = [imageName stringByAppendingString: @" _ip4" ];
109
- }
110
- UIImage *image = [UIImage imageNamed: imageName];
111
- UIImageView *imageView;
112
- if (!image) {
113
- imageView = [UIImageView new ];
114
- imageView.backgroundColor = [UIColor randomColor ];
115
- }else {
116
- imageView = [[UIImageView alloc ] initWithImage: image];
117
- }
127
+ imageName = [imageName stringByAppendingString: (kDevice_Is_iPhone6Plus ? @" _ip6+" :
128
+ kDevice_Is_iPhone6 ? @" _ip6" :
129
+ kDevice_Is_iPhone5 ? @" _ip5" :
130
+ @" _ip4" )];
131
+ UIImageView *imageView = [UIImageView new ];
132
+ imageView.userInteractionEnabled = YES ;
118
133
imageView.contentMode = UIViewContentModeScaleAspectFill;
119
134
imageView.clipsToBounds = YES ;
135
+ imageView.image = [UIImage imageNamed: imageName];
136
+ imageView.backgroundColor = imageView.image ? [UIColor clearColor ]: [UIColor randomColor ];
137
+ if (index < kIntroPageNum - 1 ) {
138
+ UIButton *button = [self p_skipButton ];
139
+ [imageView addSubview: button];
140
+ [button mas_makeConstraints: ^(MASConstraintMaker *make) {
141
+ make.size .mas_equalTo (CGSizeMake (60 , 30 ));
142
+ make.top .equalTo (imageView).offset (30 );
143
+ make.right .equalTo (imageView).offset (-20 );
144
+ }];
145
+ }else {
146
+ UIButton *button = [self p_useImmediatelyButton ];
147
+ [imageView addSubview: button];
148
+ [button mas_makeConstraints: ^(MASConstraintMaker *make) {
149
+ make.size .mas_equalTo (CGSizeMake (200 , 44 ));
150
+ make.centerX .equalTo (imageView);
151
+ make.bottom .equalTo (imageView).offset (-70 );
152
+ }];
153
+ }
120
154
EAIntroPage *page = [EAIntroPage pageWithCustomView: imageView];
121
155
return page;
122
156
}
0 commit comments