ADView.m
3.54 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// ADView.m
// IVTMeLiveTwo
//
// Created by XRG on 16/8/12.
// Copyright © 2016年 QLQ. All rights reserved.
//
#import "ADView.h"
#import "WebViewVC.h"
#import "RootTabBarController.h"
#import "IVTLoginViewController.h"
static ADView *instance = nil;
@implementation ADView{
NSDictionary *dataDict;
}
+ (ADView *)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);
self.backgroundColor = [UIColor whiteColor];
UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
imageV.backgroundColor = [UIColor whiteColor];
NSString *adurl = [IVTAccountTool getADUrl];
if (adurl.length > 0 && adurl != nil) {
[imageV sd_setImageWithURL:[NSURL URLWithString:[IVTAccountTool getADUrl]] placeholderImage:[UIImage imageNamed:@"LaunchImg"]];
}
else{
imageV.image = [UIImage imageNamed:@"LaunchImg"];
}
[self addSubview:imageV];
imageV.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
[imageV addGestureRecognizer:tap];
UIButton *skipButton = [UIButton buttonWithType:UIButtonTypeCustom];
skipButton.frame = CGRectMake(kScreenWidth-58, 50, 48, 28);
[skipButton setBackgroundImage:[UIImage imageNamed:@"跳过按钮"] forState:UIControlStateNormal];
[skipButton setTitle:@"跳过" forState:UIControlStateNormal];
[skipButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
skipButton.titleLabel.font = [UIFont systemFontOfSize:13];
[skipButton addTarget:self action:@selector(skipClick) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:skipButton];
[[IVTNetworkAPIClient sharedClient] getADImageSuccess:^(NSDictionary *successData) {
dataDict = [[successData valueForKey:@"list"] firstObject];
NSString *imageUrl = [[[successData valueForKey:@"list"] firstObject] valueForKey:@"additionData"];
[IVTAccountTool setADUrl:imageUrl];
} error:^(NSDictionary *successData) {
} failure:^(NSError *failureError) {
}];
[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(skipClick) userInfo:nil repeats:NO];
}
- (void)skipClick{
[UIView animateWithDuration:0.4 animations:^{
self.alpha = 0;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
- (void)tapAction:(UITapGestureRecognizer *)tap {
tap.enabled = NO;
NSString *urlStr = dataDict[@"conUrl"];
if (urlStr) {
RootTabBarController *tabBarVC = [RootTabBarController tabBarVC];
WebViewVC *vc = [[WebViewVC alloc] init];
vc.webUrl = urlStr;
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
if ([tabBarVC.presentedViewController isKindOfClass:[IVTLoginViewController class]]) {
[tabBarVC.presentedViewController presentViewController:nav animated:YES completion:^{
}];
} else {
[tabBarVC presentViewController:nav animated:YES completion:^{
}];
}
}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end