-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathFunctionIntroManager.m
183 lines (165 loc) · 7.42 KB
/
FunctionIntroManager.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//
// FunctionIntroManager.m
// Coding_iOS
//
// Created by Ease on 15/8/6.
// Copyright (c) 2015年 Coding. All rights reserved.
//
#define kIntroPageKey @"intro_page_version"
#define kIntroPageNum 1
#define kIntroShowSkipButton (NO)
#define kIntroShowUseImmediatelyButton (YES)
#import "FunctionIntroManager.h"
#import "EAIntroView.h"
#import "SMPageControl.h"
#import <NYXImagesKit/NYXImagesKit.h>
@interface FunctionIntroManager ()<EAIntroDelegate>
@property (strong, nonatomic) EAIntroView *introView;
@end
@implementation FunctionIntroManager
#pragma mark EAIntroPage
+ (void)showIntroPage{
if ([self needToShowIntro]) {
FunctionIntroManager *manager = [FunctionIntroManager shareManager];
[manager.introView showFullscreen];
[self markHasBeenShowed];
}
}
+ (BOOL)needToShowIntro{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *preVersion = [defaults stringForKey:kIntroPageKey];
BOOL needToShow = ([kVersion_Coding isEqualToString:@"5.0"] && kIntroPageNum > 0 && ![preVersion isEqualToString:kVersionBuild_Coding]);
return needToShow;
}
+ (void)markHasBeenShowed{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue:kVersionBuild_Coding forKey:kIntroPageKey];
[defaults synchronize];
}
+ (NSString *)p_imageNameForIndex:(NSInteger)index{
NSString *imageName = [NSString stringWithFormat:@"intro_page%ld", (long)index];
imageName = [imageName stringByAppendingString:(kDevice_Is_iPhone6Plus? @"_ip6+":
kDevice_Is_iPhone6? @"_ip6":
kDevice_Is_iPhone5? @"_ip5":
kDevice_Is_FullScreen? @"_ipX":
@"_ip4")];
return imageName;
}
#pragma mark private M
+ (instancetype)shareManager{
static FunctionIntroManager *shared_manager = nil;
static dispatch_once_t pred;
dispatch_once(&pred, ^{
shared_manager = [self new];
});
return shared_manager;
}
- (instancetype)init
{
self = [super init];
if (self) {
NSMutableArray *pages = [NSMutableArray new];
for (int index = 0; index < kIntroPageNum; index ++) {
EAIntroPage *page = [self p_pageWithIndex:index];
[pages addObject:page];
}
_introView = [[EAIntroView alloc] initWithFrame:kScreen_Bounds andPages:pages];
_introView.backgroundColor = [UIColor whiteColor];
_introView.swipeToExit = YES;
_introView.scrollView.bounces = YES;
_introView.skipButton = nil;
_introView.delegate = self;
if (pages.count <= 1) {
_introView.pageControl.hidden = YES;
}else{
_introView.pageControl = [self p_pageControl];
_introView.pageControlY = 30.f + CGRectGetHeight(_introView.pageControl.frame);
}
}
return self;
}
- (UIPageControl *)p_pageControl{
UIImage *pageIndicatorImage = [UIImage imageNamed:@"intro_page_unselected"];
UIImage *currentPageIndicatorImage = [UIImage imageNamed:@"intro_page_selected"];
// UIImage *pageIndicatorImage = [UIImage imageWithColor:[UIColor colorWithHexString:@"0x0060FF" andAlpha:.5] withFrame:CGRectMake(0, 0, 10, 3)];
// UIImage *currentPageIndicatorImage = [UIImage imageWithColor:kColorBrandBlue withFrame:CGRectMake(0, 0, 20, 3)];
if (!kDevice_Is_iPhone6 && !kDevice_Is_iPhone6Plus) {
CGFloat desginWidth = 375.0;//iPhone6 的设计尺寸
CGFloat scaleFactor = kScreen_Width/desginWidth;
pageIndicatorImage = [pageIndicatorImage scaleByFactor:scaleFactor];
currentPageIndicatorImage = [currentPageIndicatorImage scaleByFactor:scaleFactor];
}
SMPageControl *pageControl = [SMPageControl new];
pageControl.pageIndicatorImage = pageIndicatorImage;
pageControl.currentPageIndicatorImage = currentPageIndicatorImage;
[pageControl sizeToFit];
return (UIPageControl *)pageControl;
}
- (UIButton *)p_skipButton{
UIButton *button = [UIButton new];
[button addTarget:self action:@selector(dismissIntroView) forControlEvents:UIControlEventTouchUpInside];
button.titleLabel.font = [UIFont boldSystemFontOfSize:14];
button.backgroundColor = kColorNavBG;
[button setTitleColor:kColor999 forState:UIControlStateNormal];
[button setTitleColor:kColorDDD forState:UIControlStateHighlighted];
[button setTitle:@"跳过" forState:UIControlStateNormal];
[button doBorderWidth:0 color:nil cornerRadius:15.0];
return button;
}
- (UIButton *)p_useImmediatelyButton{
UIButton *button = [UIButton new];
[button addTarget:self action:@selector(dismissIntroView) forControlEvents:UIControlEventTouchUpInside];
button.titleLabel.font = [UIFont boldSystemFontOfSize:17];
button.backgroundColor = kColorBrandBlue;
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor lightTextColor] forState:UIControlStateHighlighted];
[button setTitle:@"立即体验" forState:UIControlStateNormal];
// [button doBorderWidth:0 color:nil cornerRadius:4.0];
return button;
}
- (void)dismissIntroView{
[self.introView hideWithFadeOutDuration:0.3];
}
- (EAIntroPage *)p_pageWithIndex:(NSInteger)index{
NSString *imageName = [self.class p_imageNameForIndex:index];
UIImageView *imageView = [UIImageView new];
imageView.userInteractionEnabled = YES;
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
imageView.image = [UIImage imageNamed:imageName];
imageView.backgroundColor = imageView.image? [UIColor clearColor]: [UIColor randomColor];
if (index < kIntroPageNum - 1) {
if (kIntroShowSkipButton) {
UIButton *button = [self p_skipButton];
[imageView addSubview:button];
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(60, 30));
make.top.equalTo(imageView).offset(10 + kSafeArea_Top);
make.right.equalTo(imageView).offset(-20);
}];
}
}else{
if (kIntroShowUseImmediatelyButton) {
UIButton *button = [self p_useImmediatelyButton];
[imageView addSubview:button];
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(200, (kDevice_Use_iPhone4_Layout || kDevice_Is_iPhone5)? 50: 55));
make.centerX.equalTo(imageView);
make.bottom.equalTo(imageView).offset(kDevice_Use_iPhone4_Layout? -40: kDevice_Is_iPhone5? -65: kDevice_Is_iPhone6? -70: kDevice_Is_iPhone6Plus? -90: -120);
}];
}
}
EAIntroPage *page = [EAIntroPage pageWithCustomView:imageView];
return page;
}
#pragma mark EAIntroDelegate
- (void)intro:(EAIntroView *)introView pageStartScrolling:(EAIntroPage *)page withIndex:(NSUInteger)pageIndex{
introView.pageControl.hidden = (pageIndex >= kIntroPageNum - 2 && kDevice_Use_iPhone4_Layout);
}
- (void)intro:(EAIntroView *)introView pageAppeared:(EAIntroPage *)page withIndex:(NSUInteger)pageIndex{
introView.pageControl.hidden = (pageIndex == kIntroPageNum - 1 && kDevice_Use_iPhone4_Layout);
}
- (void)intro:(EAIntroView *)introView pageEndScrolling:(EAIntroPage *)page withIndex:(NSUInteger)pageIndex{
introView.pageControl.hidden = (pageIndex == kIntroPageNum - 1 && kDevice_Use_iPhone4_Layout);
}
@end