GuideView.m
2.24 KB
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
//
// GuideView.m
// IVTMeLiveTwo
//
// Created by XRG on 16/8/12.
// Copyright © 2016年 QLQ. All rights reserved.
//
#import "GuideView.h"
static GuideView *instance = nil;
@interface GuideView ()<UIScrollViewDelegate>
@end
@implementation GuideView
+ (GuideView *)sharedInstance{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[self alloc] init];
[instance setupView];
});
return instance;
}
- (void)setupView{
self.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
UIScrollView *scrollView = [[UIScrollView alloc]init];
scrollView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
scrollView.contentOffset = CGPointMake(0, 0);
scrollView.contentSize = CGSizeMake(kScreenWidth*4, kScreenHeight);
scrollView.pagingEnabled = YES;
scrollView.directionalLockEnabled = YES;
scrollView.delegate = self;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.bounces = NO;
[self addSubview:scrollView];
NSArray *imageNameArray = [NSArray arrayWithObjects:@"guideImage1",@"guideImage2",@"guideImage3",@"guideImage4", nil];
for (NSInteger i=0; i<4; i++) {
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenWidth*i, 0, kScreenWidth, kScreenHeight)];
imageView.image = [UIImage imageNamed:imageNameArray[i]];
[scrollView addSubview:imageView];
if (i == 3) {
imageView.userInteractionEnabled = YES;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
[button addTarget:self action:@selector(goNext) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:button];
}
}
}
- (void)goNext{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kIsShowedGuideLaunchedView];
[UIView animateWithDuration:0.4 animations:^{
self.alpha = 0;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end