Skip to content

Commit 894d760

Browse files
committedSep 4, 2016
fix bug
1 parent 77cf093 commit 894d760

File tree

6 files changed

+47
-16
lines changed

6 files changed

+47
-16
lines changed
 

‎IanStartAdsView.xcodeproj/project.pbxproj

-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
3C75BE921AB012090021094E /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3C75BE911AB012090021094E /* Images.xcassets */; };
1515
3C75BEA11AB012090021094E /* IanStartAdsViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C75BEA01AB012090021094E /* IanStartAdsViewTests.m */; };
1616
3C75BEAD1AB0138F0021094E /* IanAdsStartView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C75BEAC1AB0138F0021094E /* IanAdsStartView.m */; };
17-
3C75BEAF1AB0165E0021094E /* startImage@2x.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 3C75BEAE1AB0165E0021094E /* startImage@2x.jpg */; };
1817
3C75BEE41AB030270021094E /* IanClickImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C75BEE31AB030270021094E /* IanClickImageView.m */; };
1918
3C8CD55C1D66B59E00F3901F /* GetLaunchImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C8CD55B1D66B59E00F3901F /* GetLaunchImage.m */; };
2019
3CCD3C821D6A9BE8004E7D94 /* IANWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CCD3C811D6A9BE8004E7D94 /* IANWebViewController.m */; };
@@ -44,7 +43,6 @@
4443
3C75BEA01AB012090021094E /* IanStartAdsViewTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IanStartAdsViewTests.m; sourceTree = "<group>"; };
4544
3C75BEAB1AB0138F0021094E /* IanAdsStartView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IanAdsStartView.h; sourceTree = "<group>"; };
4645
3C75BEAC1AB0138F0021094E /* IanAdsStartView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IanAdsStartView.m; sourceTree = "<group>"; };
47-
3C75BEAE1AB0165E0021094E /* startImage@2x.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "startImage@2x.jpg"; sourceTree = "<group>"; };
4846
3C75BEE21AB030270021094E /* IanClickImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IanClickImageView.h; sourceTree = "<group>"; };
4947
3C75BEE31AB030270021094E /* IanClickImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IanClickImageView.m; sourceTree = "<group>"; };
5048
3C8CD55A1D66B59E00F3901F /* GetLaunchImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GetLaunchImage.h; sourceTree = "<group>"; };
@@ -112,7 +110,6 @@
112110
3C75BE8C1AB012090021094E /* ViewController.m */,
113111
3CCD3C801D6A9BE8004E7D94 /* IANWebViewController.h */,
114112
3CCD3C811D6A9BE8004E7D94 /* IANWebViewController.m */,
115-
3C75BEAE1AB0165E0021094E /* startImage@2x.jpg */,
116113
3C75BEAA1AB013730021094E /* IanAdsStartView */,
117114
3C75BE911AB012090021094E /* Images.xcassets */,
118115
3C75BE841AB012090021094E /* Supporting Files */,
@@ -252,7 +249,6 @@
252249
buildActionMask = 2147483647;
253250
files = (
254251
3C75BE921AB012090021094E /* Images.xcassets in Resources */,
255-
3C75BEAF1AB0165E0021094E /* startImage@2x.jpg in Resources */,
256252
);
257253
runOnlyForDeploymentPostprocessing = 0;
258254
};

‎IanStartAdsView/AppDelegate.m

+18-10
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,26 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
2626
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:VC];
2727
self.window.rootViewController = nav;
2828

29-
IanAdsStartView *startView = [IanAdsStartView startAdsViewWithBgImageUrl:@"http://b.hiphotos.baidu.com/baike/c0%3Dbaike180%2C5%2C5%2C180%2C60/sign=ca5abb5b7bf0f736ccf344536b3cd87c/29381f30e924b899c83ff41c6d061d950a7bf697.jpg" withClickImageAction:^{
30-
IANWebViewController *VC = [IANWebViewController new];
31-
VC.title = @"这可能是一个广告页面";
32-
[(UINavigationController *)self.window.rootViewController pushViewController:VC animated:YES];
33-
}];
34-
35-
[startView startAnimationTime:3 WithCompletionBlock:^(IanAdsStartView *startView){
29+
NSString *picUrl = @"http://785j3g.com1.z0.glb.clouddn.com/d659db60-f.jpg";
30+
NSString *userDefaultKey = @"download_key";
3631

37-
}];
32+
if ([[[NSUserDefaults standardUserDefaults] stringForKey:userDefaultKey] isEqualToString:@"1"]) {
33+
IanAdsStartView *startView = [IanAdsStartView startAdsViewWithBgImageUrl:picUrl withClickImageAction:^{
34+
IANWebViewController *VC = [IANWebViewController new];
35+
VC.title = @"这可能是一个广告页面";
36+
[(UINavigationController *)self.window.rootViewController pushViewController:VC animated:YES];
37+
}];
38+
39+
[startView startAnimationTime:3 WithCompletionBlock:^(IanAdsStartView *startView){
40+
NSLog(@"广告结束后,执行事件");
41+
}];
42+
} else { // 第一次先下载广告
43+
[IanAdsStartView downloadStartImage:picUrl];
44+
45+
[[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:userDefaultKey];
46+
[[NSUserDefaults standardUserDefaults] synchronize];
47+
}
3848

39-
40-
4149
return YES;
4250
}
4351

‎IanStartAdsView/IanAdsStartView/IanAdsStartView.h

+2
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515

1616
- (void)startAnimationTime:(NSUInteger)time WithCompletionBlock:(void(^)(IanAdsStartView *ianStartView))completionHandler;
1717

18+
+ (void)downloadStartImage:(NSString *)imageUrl;
19+
1820
@end

‎IanStartAdsView/IanAdsStartView/IanAdsStartView.m

+26-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
@interface IanAdsStartView()
1515

16+
@property (nonatomic, strong) UIImageView *bgImageViewDefault;
1617
@property (nonatomic, strong) IanClickImageView *bgImageView;
1718
@property (nonatomic, strong) UIButton *timeButton;
1819
@property (nonatomic) BOOL isImageDownloaded;
@@ -36,6 +37,11 @@ - (instancetype)initWithBgImage:(NSString *)imageUrl withClickImageAction:(void(
3637
_isImageDownloaded = NO;
3738
_imageClickAction = action;
3839

40+
_bgImageViewDefault = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
41+
_bgImageViewDefault.contentMode = UIViewContentModeScaleToFill;
42+
[self addSubview:_bgImageViewDefault];
43+
_bgImageViewDefault.image = [GetLaunchImage getTheLaunchImage];
44+
3945
_bgImageView = [[IanClickImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
4046
_bgImageView.alpha = 0.0;
4147
_bgImageView.contentMode = UIViewContentModeScaleToFill;
@@ -113,13 +119,32 @@ - (void)startAnimationTime:(NSUInteger)time WithCompletionBlock:(void(^)(IanAdsS
113119

114120
[[UIApplication sharedApplication].keyWindow addSubview:self];
115121
[[UIApplication sharedApplication].keyWindow bringSubviewToFront:self];
116-
_bgImageView.alpha = 1.0;
122+
[UIView animateWithDuration:0.5 animations:^{
123+
_bgImageView.alpha = 1;
124+
}];
117125

118126
[_timeButton setTitle:[NSString stringWithFormat:@"跳过%zd",_timeNum] forState:UIControlStateNormal];
119127
_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];
120128

121129
}
122130

131+
+ (void)downloadStartImage:(NSString *)imageUrl
132+
{
133+
SDWebImageManager *manager = [SDWebImageManager sharedManager];
134+
BOOL cachedBool = [manager cachedImageExistsForURL:[NSURL URLWithString:imageUrl]];
135+
BOOL diskBool = [manager diskImageExistsForURL:[NSURL URLWithString:imageUrl]];
136+
if (cachedBool || diskBool) {
137+
} else {
138+
139+
[manager downloadImageWithURL:[NSURL URLWithString:imageUrl] options:SDWebImageRefreshCached progress:^(NSInteger receivedSize, NSInteger expectedSize) {
140+
141+
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
142+
143+
}];
144+
145+
}
146+
147+
}
123148

124149
#pragma mark - action method
125150

‎IanStartAdsView/ViewController.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ @implementation ViewController
1616

1717
- (void)viewDidLoad {
1818
[super viewDidLoad];
19-
self.view.backgroundColor = [UIColor redColor];
19+
self.view.backgroundColor = [UIColor whiteColor];
2020
}
2121

2222
- (void)didReceiveMemoryWarning {

‎IanStartAdsView/startImage@2x.jpg

-1.16 MB
Binary file not shown.

0 commit comments

Comments
 (0)