From 3e8437ae559487362fae3525beb79c534c213a51 Mon Sep 17 00:00:00 2001 From: 单军华 Date: Thu, 12 Jul 2018 13:44:34 +0800 Subject: [PATCH] bug修复和功能优化 --- screendisplay/screendisplay/Classes/Helpers/欢迎页/LMJIntroductoryPagesView.m | 141 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 141 insertions(+), 0 deletions(-) diff --git "a/screendisplay/screendisplay/Classes/Helpers/\346\254\242\350\277\216\351\241\265/LMJIntroductoryPagesView.m" "b/screendisplay/screendisplay/Classes/Helpers/\346\254\242\350\277\216\351\241\265/LMJIntroductoryPagesView.m" new file mode 100755 index 0000000..1f73828 --- /dev/null +++ "b/screendisplay/screendisplay/Classes/Helpers/\346\254\242\350\277\216\351\241\265/LMJIntroductoryPagesView.m" @@ -0,0 +1,141 @@ +// +// LMJIntroductoryPagesView.m +// iOSProject +// +// Created by windshan on 2017/12/29. +// Copyright �� 2017��� windshan. All rights reserved. +// + +#import "LMJIntroductoryPagesView.h" + +@interface LMJIntroductoryPagesView ()<UIScrollViewDelegate> +/** <#digest#> */ +@property (nonatomic, strong) NSArray<NSString *> *imagesArray; + +@property (nonatomic,strong) UIPageControl *pageControl; + +/** <#digest#> */ +@property (weak, nonatomic) UIScrollView *scrollView; + +@end + +@implementation LMJIntroductoryPagesView + ++ (instancetype)pagesViewWithFrame:(CGRect)frame images:(NSArray<NSString *> *)images +{ + LMJIntroductoryPagesView *pagesView = [[self alloc] initWithFrame:frame]; + pagesView.imagesArray = images; + return pagesView; +} + + + +- (void)setupUIOnce +{ + self.backgroundColor = [UIColor clearColor]; + + //������������ + UITapGestureRecognizer *singleRecognizer; + singleRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleSingleTapFrom)]; + singleRecognizer.numberOfTapsRequired = 1; + [self.scrollView addGestureRecognizer:singleRecognizer]; +} + +- (void)setImagesArray:(NSArray<NSString *> *)imagesArray { + _imagesArray = imagesArray; + [self loadPageView]; +} + +- (void)loadPageView +{ + [self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; + self.scrollView.contentSize = CGSizeMake((self.imagesArray.count + 1) * kScreenWidth, kScreenHeight); + self.pageControl.numberOfPages = self.imagesArray.count; + + [self.imagesArray enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + + YYAnimatedImageView *imageView = [[YYAnimatedImageView alloc]init]; + + imageView.frame = CGRectMake(idx * kScreenWidth, 0, kScreenWidth, kScreenHeight); + + YYImage *image = [YYImage imageNamed:obj]; + + [imageView setImage:image]; + + [self.scrollView addSubview:imageView]; + }]; +} + +-(void)handleSingleTapFrom +{ + if (_pageControl.currentPage == self.imagesArray.count-1) { + [self removeFromSuperview]; + } +} + +- (void)scrollViewDidScroll:(UIScrollView *)scrollView { + CGPoint offSet = scrollView.contentOffset; + NSInteger page = (offSet.x / (self.bounds.size.width) + 0.5); + self.pageControl.currentPage = page;//��������������������� + self.pageControl.hidden = (page > self.imagesArray.count - 1); +} + +-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView +{ + if (scrollView.contentOffset.x >= (_imagesArray.count) * kScreenWidth) { + [self removeFromSuperview]; + } +} + + +- (UIScrollView *)scrollView +{ + if(!_scrollView) + { + UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.bounds]; + [self addSubview:scrollView]; + scrollView.backgroundColor = [UIColor clearColor]; + scrollView.pagingEnabled = YES;//������������ + scrollView.bounces = NO; + scrollView.showsHorizontalScrollIndicator = NO; + scrollView.delegate = self; + _scrollView = scrollView; + } + return _scrollView; +} + +- (UIPageControl *)pageControl +{ + if(!_pageControl) + { + UIPageControl *pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(kScreenWidth/2, kScreenHeight - 60, 0, 40)]; + pageControl.backgroundColor = [UIColor RandomColor]; + pageControl.pageIndicatorTintColor = [UIColor RandomColor]; + pageControl.currentPageIndicatorTintColor = [UIColor RandomColor]; + [self addSubview:pageControl]; + _pageControl = pageControl; + } + return _pageControl; +} + +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) { + [self setupUIOnce]; + } + return self; +} + +- (void)awakeFromNib +{ + [super awakeFromNib]; + [self setupUIOnce]; +} + +- (void)layoutSubviews +{ + [super layoutSubviews]; +} + + +@end -- Gitblit v1.8.0