├── .gitignore ├── README.md ├── advertiseDemo.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── WorkspaceSettings.xcsettings ├── advertiseDemo ├── AdvertiseView.h ├── AdvertiseView.m ├── AdvertiseViewController.h ├── AdvertiseViewController.m ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ └── LaunchScreen.storyboard ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m └── resources └── 1.gif /.gitignore: -------------------------------------------------------------------------------- 1 | /Demo/Demo-Info.plist 2 | .DS_Store 3 | *.DS_Store 4 | /build/ 5 | *.pbxuser 6 | !default.pbxuser 7 | *.mode1v3 8 | !default.mode1v3 9 | *.mode2v3 10 | !default.mode2v3 11 | *.perspectivev3 12 | !default.perspectivev3 13 | xcuserdata 14 | profile 15 | *.moved-aside 16 | DerivedData 17 | .idea/ 18 | *.hmap 19 | # Pods - for those of you who use CocoaPods 20 | Pods 21 | Pods/ 22 | Podfile.lock -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | #app启动时的广告页demo 3 | 4 | 5 | ##[博客讲解地址](http://www.jianshu.com/p/ffa65292abf2) 6 | 7 | ![image](https://github.com/zhouhuanqiang/AdvertisingPageDemo/raw/master/resources/1.gif) 8 | 9 | -------------------------------------------------------------------------------- /advertiseDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 0C958EBF1CF17B3B00BC5560 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 0C958EBE1CF17B3A00BC5560 /* main.m */; }; 11 | 0C958EC21CF17B3B00BC5560 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 0C958EC11CF17B3B00BC5560 /* AppDelegate.m */; }; 12 | 0C958EC51CF17B3B00BC5560 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0C958EC41CF17B3B00BC5560 /* ViewController.m */; }; 13 | 0C958ECA1CF17B3B00BC5560 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0C958EC91CF17B3B00BC5560 /* Assets.xcassets */; }; 14 | 0C958ECD1CF17B3B00BC5560 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0C958ECB1CF17B3B00BC5560 /* LaunchScreen.storyboard */; }; 15 | 0C958ED91CF17B8500BC5560 /* AdvertiseView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0C958ED51CF17B8500BC5560 /* AdvertiseView.m */; }; 16 | 0C958EDA1CF17B8500BC5560 /* AdvertiseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0C958ED71CF17B8500BC5560 /* AdvertiseViewController.m */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 0C958EBA1CF17B3A00BC5560 /* advertiseDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = advertiseDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | 0C958EBE1CF17B3A00BC5560 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 22 | 0C958EC01CF17B3B00BC5560 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 23 | 0C958EC11CF17B3B00BC5560 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 24 | 0C958EC31CF17B3B00BC5560 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 25 | 0C958EC41CF17B3B00BC5560 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 26 | 0C958EC91CF17B3B00BC5560 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 27 | 0C958ECC1CF17B3B00BC5560 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 28 | 0C958ECE1CF17B3B00BC5560 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 29 | 0C958ED41CF17B8500BC5560 /* AdvertiseView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AdvertiseView.h; sourceTree = ""; }; 30 | 0C958ED51CF17B8500BC5560 /* AdvertiseView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AdvertiseView.m; sourceTree = ""; }; 31 | 0C958ED61CF17B8500BC5560 /* AdvertiseViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AdvertiseViewController.h; sourceTree = ""; }; 32 | 0C958ED71CF17B8500BC5560 /* AdvertiseViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AdvertiseViewController.m; sourceTree = ""; }; 33 | /* End PBXFileReference section */ 34 | 35 | /* Begin PBXFrameworksBuildPhase section */ 36 | 0C958EB71CF17B3A00BC5560 /* Frameworks */ = { 37 | isa = PBXFrameworksBuildPhase; 38 | buildActionMask = 2147483647; 39 | files = ( 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXFrameworksBuildPhase section */ 44 | 45 | /* Begin PBXGroup section */ 46 | 0C958EB11CF17B3A00BC5560 = { 47 | isa = PBXGroup; 48 | children = ( 49 | 0C958EBC1CF17B3A00BC5560 /* advertiseDemo */, 50 | 0C958EBB1CF17B3A00BC5560 /* Products */, 51 | ); 52 | sourceTree = ""; 53 | }; 54 | 0C958EBB1CF17B3A00BC5560 /* Products */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | 0C958EBA1CF17B3A00BC5560 /* advertiseDemo.app */, 58 | ); 59 | name = Products; 60 | sourceTree = ""; 61 | }; 62 | 0C958EBC1CF17B3A00BC5560 /* advertiseDemo */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | 0C958ED41CF17B8500BC5560 /* AdvertiseView.h */, 66 | 0C958ED51CF17B8500BC5560 /* AdvertiseView.m */, 67 | 0C958ED61CF17B8500BC5560 /* AdvertiseViewController.h */, 68 | 0C958ED71CF17B8500BC5560 /* AdvertiseViewController.m */, 69 | 0C958EC01CF17B3B00BC5560 /* AppDelegate.h */, 70 | 0C958EC11CF17B3B00BC5560 /* AppDelegate.m */, 71 | 0C958EC31CF17B3B00BC5560 /* ViewController.h */, 72 | 0C958EC41CF17B3B00BC5560 /* ViewController.m */, 73 | 0C958EC91CF17B3B00BC5560 /* Assets.xcassets */, 74 | 0C958ECB1CF17B3B00BC5560 /* LaunchScreen.storyboard */, 75 | 0C958ECE1CF17B3B00BC5560 /* Info.plist */, 76 | 0C958EBD1CF17B3A00BC5560 /* Supporting Files */, 77 | ); 78 | path = advertiseDemo; 79 | sourceTree = ""; 80 | }; 81 | 0C958EBD1CF17B3A00BC5560 /* Supporting Files */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | 0C958EBE1CF17B3A00BC5560 /* main.m */, 85 | ); 86 | name = "Supporting Files"; 87 | sourceTree = ""; 88 | }; 89 | /* End PBXGroup section */ 90 | 91 | /* Begin PBXNativeTarget section */ 92 | 0C958EB91CF17B3A00BC5560 /* advertiseDemo */ = { 93 | isa = PBXNativeTarget; 94 | buildConfigurationList = 0C958ED11CF17B3B00BC5560 /* Build configuration list for PBXNativeTarget "advertiseDemo" */; 95 | buildPhases = ( 96 | 0C958EB61CF17B3A00BC5560 /* Sources */, 97 | 0C958EB71CF17B3A00BC5560 /* Frameworks */, 98 | 0C958EB81CF17B3A00BC5560 /* Resources */, 99 | ); 100 | buildRules = ( 101 | ); 102 | dependencies = ( 103 | ); 104 | name = advertiseDemo; 105 | productName = advertiseDemo; 106 | productReference = 0C958EBA1CF17B3A00BC5560 /* advertiseDemo.app */; 107 | productType = "com.apple.product-type.application"; 108 | }; 109 | /* End PBXNativeTarget section */ 110 | 111 | /* Begin PBXProject section */ 112 | 0C958EB21CF17B3A00BC5560 /* Project object */ = { 113 | isa = PBXProject; 114 | attributes = { 115 | LastUpgradeCheck = 0720; 116 | ORGANIZATIONNAME = zhouhuanqiang; 117 | TargetAttributes = { 118 | 0C958EB91CF17B3A00BC5560 = { 119 | CreatedOnToolsVersion = 7.2; 120 | DevelopmentTeam = RBQ6HYJPB7; 121 | }; 122 | }; 123 | }; 124 | buildConfigurationList = 0C958EB51CF17B3A00BC5560 /* Build configuration list for PBXProject "advertiseDemo" */; 125 | compatibilityVersion = "Xcode 3.2"; 126 | developmentRegion = English; 127 | hasScannedForEncodings = 0; 128 | knownRegions = ( 129 | en, 130 | Base, 131 | ); 132 | mainGroup = 0C958EB11CF17B3A00BC5560; 133 | productRefGroup = 0C958EBB1CF17B3A00BC5560 /* Products */; 134 | projectDirPath = ""; 135 | projectRoot = ""; 136 | targets = ( 137 | 0C958EB91CF17B3A00BC5560 /* advertiseDemo */, 138 | ); 139 | }; 140 | /* End PBXProject section */ 141 | 142 | /* Begin PBXResourcesBuildPhase section */ 143 | 0C958EB81CF17B3A00BC5560 /* Resources */ = { 144 | isa = PBXResourcesBuildPhase; 145 | buildActionMask = 2147483647; 146 | files = ( 147 | 0C958ECD1CF17B3B00BC5560 /* LaunchScreen.storyboard in Resources */, 148 | 0C958ECA1CF17B3B00BC5560 /* Assets.xcassets in Resources */, 149 | ); 150 | runOnlyForDeploymentPostprocessing = 0; 151 | }; 152 | /* End PBXResourcesBuildPhase section */ 153 | 154 | /* Begin PBXSourcesBuildPhase section */ 155 | 0C958EB61CF17B3A00BC5560 /* Sources */ = { 156 | isa = PBXSourcesBuildPhase; 157 | buildActionMask = 2147483647; 158 | files = ( 159 | 0C958ED91CF17B8500BC5560 /* AdvertiseView.m in Sources */, 160 | 0C958EC51CF17B3B00BC5560 /* ViewController.m in Sources */, 161 | 0C958EDA1CF17B8500BC5560 /* AdvertiseViewController.m in Sources */, 162 | 0C958EC21CF17B3B00BC5560 /* AppDelegate.m in Sources */, 163 | 0C958EBF1CF17B3B00BC5560 /* main.m in Sources */, 164 | ); 165 | runOnlyForDeploymentPostprocessing = 0; 166 | }; 167 | /* End PBXSourcesBuildPhase section */ 168 | 169 | /* Begin PBXVariantGroup section */ 170 | 0C958ECB1CF17B3B00BC5560 /* LaunchScreen.storyboard */ = { 171 | isa = PBXVariantGroup; 172 | children = ( 173 | 0C958ECC1CF17B3B00BC5560 /* Base */, 174 | ); 175 | name = LaunchScreen.storyboard; 176 | sourceTree = ""; 177 | }; 178 | /* End PBXVariantGroup section */ 179 | 180 | /* Begin XCBuildConfiguration section */ 181 | 0C958ECF1CF17B3B00BC5560 /* Debug */ = { 182 | isa = XCBuildConfiguration; 183 | buildSettings = { 184 | ALWAYS_SEARCH_USER_PATHS = NO; 185 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 186 | CLANG_CXX_LIBRARY = "libc++"; 187 | CLANG_ENABLE_MODULES = YES; 188 | CLANG_ENABLE_OBJC_ARC = YES; 189 | CLANG_WARN_BOOL_CONVERSION = YES; 190 | CLANG_WARN_CONSTANT_CONVERSION = YES; 191 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 192 | CLANG_WARN_EMPTY_BODY = YES; 193 | CLANG_WARN_ENUM_CONVERSION = YES; 194 | CLANG_WARN_INT_CONVERSION = YES; 195 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 196 | CLANG_WARN_UNREACHABLE_CODE = YES; 197 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 198 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 199 | COPY_PHASE_STRIP = NO; 200 | DEBUG_INFORMATION_FORMAT = dwarf; 201 | ENABLE_STRICT_OBJC_MSGSEND = YES; 202 | ENABLE_TESTABILITY = YES; 203 | GCC_C_LANGUAGE_STANDARD = gnu99; 204 | GCC_DYNAMIC_NO_PIC = NO; 205 | GCC_NO_COMMON_BLOCKS = YES; 206 | GCC_OPTIMIZATION_LEVEL = 0; 207 | GCC_PREPROCESSOR_DEFINITIONS = ( 208 | "DEBUG=1", 209 | "$(inherited)", 210 | ); 211 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 212 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 213 | GCC_WARN_UNDECLARED_SELECTOR = YES; 214 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 215 | GCC_WARN_UNUSED_FUNCTION = YES; 216 | GCC_WARN_UNUSED_VARIABLE = YES; 217 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 218 | MTL_ENABLE_DEBUG_INFO = YES; 219 | ONLY_ACTIVE_ARCH = YES; 220 | SDKROOT = iphoneos; 221 | }; 222 | name = Debug; 223 | }; 224 | 0C958ED01CF17B3B00BC5560 /* Release */ = { 225 | isa = XCBuildConfiguration; 226 | buildSettings = { 227 | ALWAYS_SEARCH_USER_PATHS = NO; 228 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 229 | CLANG_CXX_LIBRARY = "libc++"; 230 | CLANG_ENABLE_MODULES = YES; 231 | CLANG_ENABLE_OBJC_ARC = YES; 232 | CLANG_WARN_BOOL_CONVERSION = YES; 233 | CLANG_WARN_CONSTANT_CONVERSION = YES; 234 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 235 | CLANG_WARN_EMPTY_BODY = YES; 236 | CLANG_WARN_ENUM_CONVERSION = YES; 237 | CLANG_WARN_INT_CONVERSION = YES; 238 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 239 | CLANG_WARN_UNREACHABLE_CODE = YES; 240 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 241 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 242 | COPY_PHASE_STRIP = NO; 243 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 244 | ENABLE_NS_ASSERTIONS = NO; 245 | ENABLE_STRICT_OBJC_MSGSEND = YES; 246 | GCC_C_LANGUAGE_STANDARD = gnu99; 247 | GCC_NO_COMMON_BLOCKS = YES; 248 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 249 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 250 | GCC_WARN_UNDECLARED_SELECTOR = YES; 251 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 252 | GCC_WARN_UNUSED_FUNCTION = YES; 253 | GCC_WARN_UNUSED_VARIABLE = YES; 254 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 255 | MTL_ENABLE_DEBUG_INFO = NO; 256 | SDKROOT = iphoneos; 257 | VALIDATE_PRODUCT = YES; 258 | }; 259 | name = Release; 260 | }; 261 | 0C958ED21CF17B3B00BC5560 /* Debug */ = { 262 | isa = XCBuildConfiguration; 263 | buildSettings = { 264 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 265 | CODE_SIGN_IDENTITY = "iPhone Developer"; 266 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 267 | INFOPLIST_FILE = advertiseDemo/Info.plist; 268 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 269 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 270 | PRODUCT_BUNDLE_IDENTIFIER = com.zhq.advertiseDemo; 271 | PRODUCT_NAME = "$(TARGET_NAME)"; 272 | PROVISIONING_PROFILE = ""; 273 | }; 274 | name = Debug; 275 | }; 276 | 0C958ED31CF17B3B00BC5560 /* Release */ = { 277 | isa = XCBuildConfiguration; 278 | buildSettings = { 279 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 280 | CODE_SIGN_IDENTITY = "iPhone Developer"; 281 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 282 | INFOPLIST_FILE = advertiseDemo/Info.plist; 283 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 284 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 285 | PRODUCT_BUNDLE_IDENTIFIER = com.zhq.advertiseDemo; 286 | PRODUCT_NAME = "$(TARGET_NAME)"; 287 | PROVISIONING_PROFILE = ""; 288 | }; 289 | name = Release; 290 | }; 291 | /* End XCBuildConfiguration section */ 292 | 293 | /* Begin XCConfigurationList section */ 294 | 0C958EB51CF17B3A00BC5560 /* Build configuration list for PBXProject "advertiseDemo" */ = { 295 | isa = XCConfigurationList; 296 | buildConfigurations = ( 297 | 0C958ECF1CF17B3B00BC5560 /* Debug */, 298 | 0C958ED01CF17B3B00BC5560 /* Release */, 299 | ); 300 | defaultConfigurationIsVisible = 0; 301 | defaultConfigurationName = Release; 302 | }; 303 | 0C958ED11CF17B3B00BC5560 /* Build configuration list for PBXNativeTarget "advertiseDemo" */ = { 304 | isa = XCConfigurationList; 305 | buildConfigurations = ( 306 | 0C958ED21CF17B3B00BC5560 /* Debug */, 307 | 0C958ED31CF17B3B00BC5560 /* Release */, 308 | ); 309 | defaultConfigurationIsVisible = 0; 310 | defaultConfigurationName = Release; 311 | }; 312 | /* End XCConfigurationList section */ 313 | }; 314 | rootObject = 0C958EB21CF17B3A00BC5560 /* Project object */; 315 | } 316 | -------------------------------------------------------------------------------- /advertiseDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /advertiseDemo.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /advertiseDemo/AdvertiseView.h: -------------------------------------------------------------------------------- 1 | // 2 | // AdvertiseView.h 3 | // zhibo 4 | // 5 | // Created by 周焕强 on 16/5/17. 6 | // Copyright © 2016年 zhq. All rights reserved. 7 | // 8 | 9 | #import 10 | #define kscreenWidth [UIScreen mainScreen].bounds.size.width 11 | #define kscreenHeight [UIScreen mainScreen].bounds.size.height 12 | #define kUserDefaults [NSUserDefaults standardUserDefaults] 13 | static NSString *const adImageName = @"adImageName"; 14 | static NSString *const adUrl = @"adUrl"; 15 | @interface AdvertiseView : UIView 16 | 17 | /** 显示广告页面方法*/ 18 | - (void)show; 19 | 20 | /** 图片路径*/ 21 | @property (nonatomic, copy) NSString *filePath; 22 | 23 | 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /advertiseDemo/AdvertiseView.m: -------------------------------------------------------------------------------- 1 | // 2 | // AdvertiseView.m 3 | // zhibo 4 | // 5 | // Created by 周焕强 on 16/5/17. 6 | // Copyright © 2016年 zhq. All rights reserved. 7 | // 8 | 9 | #import "AdvertiseView.h" 10 | 11 | @interface AdvertiseView() 12 | 13 | @property (nonatomic, strong) UIImageView *adView; 14 | 15 | @property (nonatomic, strong) UIButton *countBtn; 16 | 17 | @property (nonatomic, strong) NSTimer *countTimer; 18 | 19 | @property (nonatomic, assign) int count; 20 | 21 | @end 22 | 23 | // 广告显示的时间 24 | static int const showtime = 3; 25 | 26 | @implementation AdvertiseView 27 | 28 | - (NSTimer *)countTimer 29 | { 30 | if (!_countTimer) { 31 | _countTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDown) userInfo:nil repeats:YES]; 32 | } 33 | return _countTimer; 34 | } 35 | 36 | - (instancetype)initWithFrame:(CGRect)frame 37 | { 38 | if (self = [super initWithFrame:frame]) { 39 | 40 | // 1.广告图片 41 | _adView = [[UIImageView alloc] initWithFrame:frame]; 42 | _adView.userInteractionEnabled = YES; 43 | _adView.contentMode = UIViewContentModeScaleAspectFill; 44 | _adView.clipsToBounds = YES; 45 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToAd)]; 46 | [_adView addGestureRecognizer:tap]; 47 | 48 | // 2.跳过按钮 49 | CGFloat btnW = 60; 50 | CGFloat btnH = 30; 51 | _countBtn = [[UIButton alloc] initWithFrame:CGRectMake(kscreenWidth - btnW - 24, btnH, btnW, btnH)]; 52 | [_countBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside]; 53 | [_countBtn setTitle:[NSString stringWithFormat:@"跳过%d", showtime] forState:UIControlStateNormal]; 54 | _countBtn.titleLabel.font = [UIFont systemFontOfSize:15]; 55 | [_countBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 56 | _countBtn.backgroundColor = [UIColor colorWithRed:38 /255.0 green:38 /255.0 blue:38 /255.0 alpha:0.6]; 57 | _countBtn.layer.cornerRadius = 4; 58 | 59 | [self addSubview:_adView]; 60 | [self addSubview:_countBtn]; 61 | 62 | } 63 | return self; 64 | } 65 | 66 | - (void)setFilePath:(NSString *)filePath 67 | { 68 | _filePath = filePath; 69 | _adView.image = [UIImage imageWithContentsOfFile:filePath]; 70 | } 71 | 72 | - (void)pushToAd{ 73 | 74 | [self dismiss]; 75 | 76 | [[NSNotificationCenter defaultCenter] postNotificationName:@"pushtoad" object:nil userInfo:nil]; 77 | } 78 | 79 | - (void)countDown 80 | { 81 | _count --; 82 | [_countBtn setTitle:[NSString stringWithFormat:@"跳过%d",_count] forState:UIControlStateNormal]; 83 | if (_count == 0) { 84 | 85 | [self dismiss]; 86 | } 87 | } 88 | 89 | - (void)show 90 | { 91 | // 倒计时方法1:GCD 92 | // [self startCoundown]; 93 | 94 | // 倒计时方法2:定时器 95 | [self startTimer]; 96 | UIWindow *window = [UIApplication sharedApplication].keyWindow; 97 | [window addSubview:self]; 98 | } 99 | 100 | // 定时器倒计时 101 | - (void)startTimer 102 | { 103 | _count = showtime; 104 | [[NSRunLoop mainRunLoop] addTimer:self.countTimer forMode:NSRunLoopCommonModes]; 105 | } 106 | 107 | // GCD倒计时 108 | - (void)startCoundown 109 | { 110 | __block int timeout = showtime + 1; //倒计时时间 + 1 111 | dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 112 | dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue); 113 | dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0 * NSEC_PER_SEC, 0); //每秒执行 114 | dispatch_source_set_event_handler(_timer, ^{ 115 | if(timeout <= 0){ //倒计时结束,关闭 116 | dispatch_source_cancel(_timer); 117 | dispatch_async(dispatch_get_main_queue(), ^{ 118 | 119 | [self dismiss]; 120 | 121 | }); 122 | }else{ 123 | 124 | dispatch_async(dispatch_get_main_queue(), ^{ 125 | [_countBtn setTitle:[NSString stringWithFormat:@"跳过%d",timeout] forState:UIControlStateNormal]; 126 | }); 127 | timeout--; 128 | } 129 | }); 130 | dispatch_resume(_timer); 131 | } 132 | 133 | // 移除广告页面 134 | - (void)dismiss 135 | { 136 | [self.countTimer invalidate]; 137 | self.countTimer = nil; 138 | 139 | [UIView animateWithDuration:0.3f animations:^{ 140 | 141 | self.alpha = 0.f; 142 | 143 | } completion:^(BOOL finished) { 144 | 145 | [self removeFromSuperview]; 146 | 147 | }]; 148 | 149 | } 150 | 151 | 152 | @end 153 | -------------------------------------------------------------------------------- /advertiseDemo/AdvertiseViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // AdvertiseViewController.h 3 | // zhibo 4 | // 5 | // Created by 周焕强 on 16/5/17. 6 | // Copyright © 2016年 zhq. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AdvertiseViewController : UIViewController 12 | 13 | @property (nonatomic, copy) NSString *adUrl; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /advertiseDemo/AdvertiseViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // AdvertiseViewController.m 3 | // zhibo 4 | // 5 | // Created by 周焕强 on 16/5/17. 6 | // Copyright © 2016年 zhq. All rights reserved. 7 | // 8 | 9 | #import "AdvertiseViewController.h" 10 | 11 | @interface AdvertiseViewController () 12 | 13 | @property (nonatomic, strong) UIWebView *webView; 14 | 15 | @end 16 | 17 | @implementation AdvertiseViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | self.title = @"点击进入广告链接"; 22 | _webView = [[UIWebView alloc] initWithFrame:self.view.bounds]; 23 | _webView.backgroundColor = [UIColor whiteColor]; 24 | if (!self.adUrl) { 25 | self.adUrl = @"http://www.jianshu.com"; 26 | } 27 | NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.adUrl]]; 28 | [_webView loadRequest:request]; 29 | [self.view addSubview:_webView]; 30 | } 31 | 32 | - (void)setAdUrl:(NSString *)adUrl 33 | { 34 | _adUrl = adUrl; 35 | } 36 | 37 | 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /advertiseDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // advertiseDemo 4 | // 5 | // Created by zhouhuanqiang on 16/5/22. 6 | // Copyright © 2016年 zhouhuanqiang. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /advertiseDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // advertiseDemo 4 | // 5 | // Created by zhouhuanqiang on 16/5/22. 6 | // Copyright © 2016年 zhouhuanqiang. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "ViewController.h" 11 | #import "AdvertiseView.h" 12 | 13 | @interface AppDelegate () 14 | 15 | @property (nonatomic, strong)UIImageView *advertiseView; 16 | 17 | @end 18 | 19 | @implementation AppDelegate 20 | 21 | 22 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 23 | 24 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 25 | 26 | self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]]; 27 | 28 | [self.window makeKeyAndVisible]; 29 | 30 | // 1.判断沙盒中是否存在广告图片,如果存在,直接显示 31 | NSString *filePath = [self getFilePathWithImageName:[kUserDefaults valueForKey:adImageName]]; 32 | 33 | BOOL isExist = [self isFileExistWithFilePath:filePath]; 34 | if (isExist) {// 图片存在 35 | 36 | AdvertiseView *advertiseView = [[AdvertiseView alloc] initWithFrame:self.window.bounds]; 37 | advertiseView.filePath = filePath; 38 | [advertiseView show]; 39 | 40 | } 41 | 42 | // 2.无论沙盒中是否存在广告图片,都需要重新调用广告接口,判断广告是否更新 43 | [self getAdvertisingImage]; 44 | 45 | return YES; 46 | } 47 | 48 | 49 | 50 | /** 51 | * 判断文件是否存在 52 | */ 53 | - (BOOL)isFileExistWithFilePath:(NSString *)filePath 54 | { 55 | NSFileManager *fileManager = [NSFileManager defaultManager]; 56 | BOOL isDirectory = FALSE; 57 | return [fileManager fileExistsAtPath:filePath isDirectory:&isDirectory]; 58 | } 59 | 60 | /** 61 | * 初始化广告页面 62 | */ 63 | - (void)getAdvertisingImage 64 | { 65 | 66 | // TODO 请求广告接口 67 | 68 | // 这里原本采用美团的广告接口,现在了一些固定的图片url代替 69 | NSArray *imageArray = @[@"http://imgsrc.baidu.com/forum/pic/item/9213b07eca80653846dc8fab97dda144ad348257.jpg", @"http://pic.paopaoche.net/up/2012-2/20122220201612322865.png", @"http://img5.pcpop.com/ArticleImages/picshow/0x0/20110801/2011080114495843125.jpg", @"http://www.mangowed.com/uploads/allimg/130410/1-130410215449417.jpg"]; 70 | NSString *imageUrl = imageArray[arc4random() % imageArray.count]; 71 | 72 | // 获取图片名:43-130P5122Z60-50.jpg 73 | NSArray *stringArr = [imageUrl componentsSeparatedByString:@"/"]; 74 | NSString *imageName = stringArr.lastObject; 75 | 76 | // 拼接沙盒路径 77 | NSString *filePath = [self getFilePathWithImageName:imageName]; 78 | BOOL isExist = [self isFileExistWithFilePath:filePath]; 79 | if (!isExist){// 如果该图片不存在,则删除老图片,下载新图片 80 | 81 | [self downloadAdImageWithUrl:imageUrl imageName:imageName]; 82 | 83 | } 84 | 85 | } 86 | 87 | /** 88 | * 下载新图片 89 | */ 90 | - (void)downloadAdImageWithUrl:(NSString *)imageUrl imageName:(NSString *)imageName 91 | { 92 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 93 | 94 | NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]; 95 | UIImage *image = [UIImage imageWithData:data]; 96 | 97 | NSString *filePath = [self getFilePathWithImageName:imageName]; // 保存文件的名称 98 | 99 | if ([UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES]) {// 保存成功 100 | NSLog(@"保存成功"); 101 | [self deleteOldImage]; 102 | [kUserDefaults setValue:imageName forKey:adImageName]; 103 | [kUserDefaults synchronize]; 104 | // 如果有广告链接,将广告链接也保存下来 105 | }else{ 106 | NSLog(@"保存失败"); 107 | } 108 | 109 | }); 110 | } 111 | 112 | /** 113 | * 删除旧图片 114 | */ 115 | - (void)deleteOldImage 116 | { 117 | NSString *imageName = [kUserDefaults valueForKey:adImageName]; 118 | if (imageName) { 119 | NSString *filePath = [self getFilePathWithImageName:imageName]; 120 | NSFileManager *fileManager = [NSFileManager defaultManager]; 121 | [fileManager removeItemAtPath:filePath error:nil]; 122 | } 123 | } 124 | 125 | /** 126 | * 根据图片名拼接文件路径 127 | */ 128 | - (NSString *)getFilePathWithImageName:(NSString *)imageName 129 | { 130 | if (imageName) { 131 | 132 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES); 133 | NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:imageName]; 134 | 135 | return filePath; 136 | } 137 | 138 | return nil; 139 | } 140 | 141 | @end -------------------------------------------------------------------------------- /advertiseDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /advertiseDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /advertiseDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | NSAppTransportSecurity 26 | 27 | NSAllowsArbitraryLoads 28 | 29 | 30 | UILaunchStoryboardName 31 | LaunchScreen 32 | UIRequiredDeviceCapabilities 33 | 34 | armv7 35 | 36 | UISupportedInterfaceOrientations 37 | 38 | UIInterfaceOrientationPortrait 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /advertiseDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // advertiseDemo 4 | // 5 | // Created by zhouhuanqiang on 16/5/22. 6 | // Copyright © 2016年 zhouhuanqiang. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /advertiseDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // advertiseDemo 4 | // 5 | // Created by zhouhuanqiang on 16/5/22. 6 | // Copyright © 2016年 zhouhuanqiang. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "AdvertiseViewController.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | 21 | self.title = @"首页"; 22 | 23 | self.view.backgroundColor = [UIColor orangeColor]; 24 | 25 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToAd) name:@"pushtoad" object:nil]; 26 | } 27 | 28 | - (void)pushToAd { 29 | 30 | AdvertiseViewController *adVc = [[AdvertiseViewController alloc] init]; 31 | [self.navigationController pushViewController:adVc animated:YES]; 32 | 33 | } 34 | 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /advertiseDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // advertiseDemo 4 | // 5 | // Created by zhouhuanqiang on 16/5/22. 6 | // Copyright © 2016年 zhouhuanqiang. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /resources/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhouhuanqiang/AdvertisingPageDemo/a67b1141a4d5532a2e51e26ddcc798fd28d11e10/resources/1.gif --------------------------------------------------------------------------------