Skip to content

Commit c42ba6a

Browse files
committed
update
1 parent 8b72c46 commit c42ba6a

File tree

5 files changed

+87
-22
lines changed

5 files changed

+87
-22
lines changed

KSGuide.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "KSGuide"
19-
s.version = "1.4"
19+
s.version = "1.5"
2020
s.summary = "iOS App first start guide."
2121

2222
# This description is used to generate tags and improve search results.
@@ -85,7 +85,7 @@ Pod::Spec.new do |s|
8585
# Supports git, hg, bzr, svn and HTTP.
8686
#
8787

88-
s.source = { :git => "https://github.com/bing6/KSGuide.git", :tag => "1.4" }
88+
s.source = { :git => "https://github.com/bing6/KSGuide.git", :tag => "1.5" }
8989

9090

9191
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

KSGuide/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.4</string>
18+
<string>1.5</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
22-
<string>1.4</string>
22+
<string>1.5</string>
2323
<key>LSRequiresIPhoneOS</key>
2424
<true/>
2525
<key>UILaunchStoryboardName</key>

KSGuide/ViewController.m

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,40 @@ - (void)viewDidLoad {
3030
[[KSGuideManager shared] setDelegate:self];
3131
//设置退出动画效果
3232
[[KSGuideManager shared] setAnimationType:KSGuideAnimationTypeTop];
33-
// [[KSGuideManager shared] clearMark];
33+
[[KSGuideManager shared] clearMark];
3434
[[KSGuideManager shared] showGuideViewWithImages:paths];
35+
36+
37+
//
3538
}
3639

3740
- (void)didReceiveMemoryWarning {
3841
[super didReceiveMemoryWarning];
3942
// Dispose of any resources that can be recreated.
4043
}
4144

45+
- (void)T:(id)sender {
46+
[[KSGuideManager shared] hideGuideView];
47+
}
48+
49+
- (void)KSGuidDidShowView:(id)sender {
50+
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
51+
[button setFrame:CGRectMake(0, 0, 200, 44)];
52+
[button setTitle:@"Hi~~" forState:UIControlStateNormal];
53+
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
54+
[button.layer setCornerRadius:5];
55+
[button.layer setBorderColor:[UIColor grayColor].CGColor];
56+
[button.layer setBorderWidth:1.0f];
57+
[button setBackgroundColor:[UIColor whiteColor]];
58+
[button addTarget:self action:@selector(T:) forControlEvents:UIControlEventTouchUpInside];
59+
60+
[[KSGuideManager shared].contentView addSubview:button];
61+
}
62+
63+
- (BOOL)isShowPageControl {
64+
return false;
65+
}
66+
4267
- (UIButton *)KSGuidLastPageButton {
4368
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
4469
[button setFrame:CGRectMake(0, 0, 200, 44)];

src/KSGuideManager.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ typedef enum : NSUInteger {
2323
@protocol KSGuideDelegate <NSObject>
2424

2525
@optional
26+
27+
- (void)KSGuidDidShowView:(id)sender;
28+
29+
/**
30+
是否显示分页
31+
32+
@return 是否
33+
*/
34+
- (BOOL)isShowPageControl;
2635
/**
2736
* 设置最后一页的跳转Button
2837
*
@@ -39,6 +48,7 @@ typedef enum : NSUInteger {
3948

4049
@interface KSGuideManager : NSObject
4150

51+
@property (nonatomic, strong, readonly) UIView *contentView;
4252
/**
4353
* 退出时动画效果,默认为淡出
4454
*/
@@ -72,4 +82,9 @@ typedef enum : NSUInteger {
7282
*/
7383
- (BOOL)showGuideViewWithImages:(NSArray *)images;
7484

85+
/**
86+
隐藏引导图
87+
*/
88+
- (void)hideGuideView;
89+
7590
@end

src/KSGuideManager.m

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ - (void)myInit {
4141
self.imageView = [[UIImageView alloc] init];
4242
self.imageView.frame = kScreenBounds;
4343
self.imageView.center = CGPointMake(kScreenBounds.size.width / 2, kScreenBounds.size.height / 2);
44-
44+
self.imageView.contentMode = UIViewContentModeScaleAspectFill;
45+
4546
[self.contentView addSubview:self.imageView];
4647
}
4748

@@ -50,13 +51,14 @@ - (void)myInit {
5051
@interface KSGuideManager ()<UICollectionViewDelegate, UICollectionViewDataSource, UIScrollViewDelegate>
5152

5253
@property (nonatomic, strong) UIWindow *window;
53-
@property (nonatomic, strong) UICollectionView *view;
5454
@property (nonatomic, strong) NSArray *images;
5555
@property (nonatomic, strong) UIPageControl *pageControl;
56+
@property (nonatomic, strong) UICollectionView *view;
5657

5758
@end
5859

5960
@implementation KSGuideManager
61+
@synthesize contentView = _contentView;
6062

6163
- (instancetype)init
6264
{
@@ -77,6 +79,13 @@ + (instancetype)shared {
7779
return __staticObject;
7880
}
7981

82+
- (UIView *)contentView {
83+
if (!_contentView) {
84+
_contentView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
85+
}
86+
return _contentView;
87+
}
88+
8089
- (UICollectionView *)view {
8190
if (_view == nil) {
8291

@@ -124,18 +133,23 @@ - (BOOL)showGuideViewWithImages:(NSArray *)images {
124133
NSString *version = [[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleShortVersionString"];
125134
//根据版本号来区分是否要显示引导图
126135
BOOL show = [ud boolForKey:[NSString stringWithFormat:@"KSGuide_%@", version]];
127-
128-
129-
136+
130137
if (!show && self.window == nil) {
131138

132139
self.images = images;
133140
self.pageControl.numberOfPages = images.count;
134141
self.window = [UIApplication sharedApplication].keyWindow;
135142

136-
[self.window addSubview:self.view];
137-
[self.window addSubview:self.pageControl];
143+
[self.contentView addSubview:self.view];
144+
[self.contentView addSubview:self.pageControl];
145+
[self.window addSubview:self.contentView];
138146

147+
if ([self.delegate respondsToSelector:@selector(isShowPageControl)]) {
148+
self.pageControl.hidden = !([self.delegate isShowPageControl]);
149+
}
150+
if ([self.delegate respondsToSelector:@selector(KSGuidDidShowView:)]) {
151+
[self.delegate KSGuidDidShowView:self];
152+
}
139153
[ud setBool:YES forKey:[NSString stringWithFormat:@"KSGuide_%@", version]];
140154
[ud synchronize];
141155
return YES;
@@ -156,13 +170,13 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
156170
KSGuideViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
157171

158172
NSString *path = [self.images objectAtIndex:indexPath.row];
159-
UIImage *img = [UIImage imageWithContentsOfFile:path];
160-
CGSize size = [self adapterSizeImageSize:img.size compareSize:kScreenBounds.size];
161-
162-
//自适应图片位置,图片可以是任意尺寸,会自动缩放.
163-
cell.imageView.frame = CGRectMake(0, 0, size.width, size.height);
173+
// UIImage *img = [UIImage imageWithContentsOfFile:path];
174+
// CGSize size = [self adapterSizeImageSize:img.size compareSize:kScreenBounds.size];
175+
//
176+
// //自适应图片位置,图片可以是任意尺寸,会自动缩放.
177+
cell.imageView.frame = CGRectMake(0, 0, kScreenBounds.size.width, kScreenBounds.size.height);
164178
cell.imageView.image = [UIImage imageWithContentsOfFile:path];
165-
cell.imageView.center = CGPointMake(kScreenBounds.size.width / 2, kScreenBounds.size.height / 2);
179+
// cell.imageView.center = CGPointMake(kScreenBounds.size.width / 2, kScreenBounds.size.height / 2);
166180

167181
if (indexPath.row == self.images.count - 1) {
168182
if (cell.button == nil) {
@@ -172,8 +186,10 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
172186
} else {
173187
cell.button = [self defaultButton];
174188
}
175-
[cell.button addTarget:self action:@selector(nextButtonHandler:) forControlEvents:UIControlEventTouchUpInside];
176-
[cell.contentView addSubview:cell.button];
189+
if (cell.button) {
190+
[cell.button addTarget:self action:@selector(nextButtonHandler:) forControlEvents:UIControlEventTouchUpInside];
191+
[cell.contentView addSubview:cell.button];
192+
}
177193
}
178194
} else {
179195
if (cell.button != nil) {
@@ -214,6 +230,10 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
214230
self.pageControl.currentPage = (scrollView.contentOffset.x / kScreenBounds.size.width);
215231
}
216232

233+
- (void)hideGuideView {
234+
[self nextButtonHandler:nil];
235+
}
236+
217237
- (void)nextButtonHandler:(id)sender {
218238

219239
if (self.animationType != KSGuideAnimationTypeNothing) {
@@ -236,16 +256,21 @@ - (void)nextButtonHandler:(id)sender {
236256
} completion:^(BOOL finished) {
237257
[ws.pageControl removeFromSuperview];
238258
[ws.view removeFromSuperview];
259+
[ws.contentView removeFromSuperview];
239260
[ws setWindow:nil];
240-
[ws setView:nil];
241261
[ws setPageControl:nil];
262+
[self setView:nil];
263+
_contentView = nil;
242264
}];
243265
} else {
244266
[self.pageControl removeFromSuperview];
245267
[self.view removeFromSuperview];
268+
[self.contentView removeFromSuperview];
246269
[self setWindow:nil];
247-
[self setView:nil];
248270
[self setPageControl:nil];
271+
[self setView:nil];
272+
_contentView = nil;
273+
249274
}
250275

251276
if (self.delegate && [self.delegate respondsToSelector:@selector(KSGuidLastPageButtonDidOnClick)]) {

0 commit comments

Comments
 (0)