@@ -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