123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- //
- // SingleGuideView.m
- // DDTG
- //
- // Created by 翟玉磊 on 2017/7/10.
- // Copyright © 2017年 翟玉磊. All rights reserved.
- //
- #import "SingleGuideView.h"
- @interface SingleGuideView ()
- @property (strong, nonatomic) NSArray *imageArray;
- @property (nonatomic, strong) UIImageView *imageView;
- @property (nonatomic, strong) UIButton *touchButton;
- @property (nonatomic, copy) SingleGuideViewBlock callback;
- @end
- @implementation SingleGuideView
- static SingleGuideView *singleGuideView = nil;
- static dispatch_once_t onceToken;
- + (instancetype)sharedView {
- dispatch_once(&onceToken, ^{
- CGRect frame = [UIScreen mainScreen].bounds;
- singleGuideView = [[SingleGuideView alloc] initWithFrame:frame];
- [[UIApplication sharedApplication].delegate.window addSubview:singleGuideView];
- });
- return singleGuideView;
- }
- - (instancetype)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
-
- self.backgroundColor = [UIColor clearColor];
- [self buildView];
- }
- return self;
- }
- - (void)buildView {
- [self addSubview:self.imageView];
- [self addSubview:self.touchButton];
- }
- - (void)setupImage:(NSArray *)images block:(SingleGuideViewBlock)callback {
- if (images.count == 0) {
- [self dismiss:callback];
- return;
- }
- self.callback = callback;
- _imageArray = [NSArray arrayWithArray:images];
- [self show];
- self.imageView.image = _imageArray[0];
- self.touchButton.tag = 0;
- }
- - (void)touchButtonAction:(UIButton *)sender {
- if (sender.tag == self.imageArray.count - 1) {
- [self dismiss:self.callback];
- } else {
- sender.tag += 1;
- self.imageView.image = self.imageArray[sender.tag];
- }
- }
- - (void)show {
- self.alpha = 1;
- self.hidden = NO;
- }
- - (void)dismiss:(SingleGuideViewBlock)callback {
-
- [UIView animateWithDuration:.3 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
- self.alpha = 0;
- } completion:^(BOOL finished) {
- self.hidden = YES;
- if (callback) {
- callback();
- }
- }];
- }
- + (void)destroyInstance {
- onceToken = 0;
- singleGuideView = nil;
- }
- #pragma mark - Get
- - (UIImageView *)imageView {
- if (_imageView == nil) {
- _imageView = [[UIImageView alloc] initWithFrame:self.bounds];
- _imageView.backgroundColor = [UIColor clearColor];
- }
- return _imageView;
- }
- - (UIButton *)touchButton {
- if (_touchButton == nil) {
- _touchButton = [UIButton buttonWithType:UIButtonTypeCustom];
- _touchButton.frame = self.bounds;
- _touchButton.backgroundColor = [UIColor clearColor];
- [_touchButton addTarget:self action:@selector(touchButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _touchButton;
- }
- @end
|