您的位置:首页 > 移动开发 > Swift

Swift - 集成app启动页广告,切换rootViewController,支持LaunchImage和LaunchScreen.storyboard,支持GIF图片显示,支持视图过渡动画

2017-07-31 13:16 3051 查看
以前的OC项目中使用自定义view做启动页广告,发现存在一些问题:

广告图片之前会先闪出根视图,再出现广告图

首页需要弹出一些视图:如版本更新、弹窗广告、新手引导等,层级太多,逻辑比较复杂

swift 集成app启动页广告,切换rootViewController,支持LaunchImage和LaunchScreen.storyboard,支持GIF图片显示,支持视图过渡动画













附上GitHub:https://github.com/MQZHot/ZLaunchAdVC

不足之处,欢迎指出错误,欢迎star✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨

功能

圆形进度跳过、倒计时跳过

广告图大小设置

自定义跳过按钮,自定义位置、大小、颜色。。。

支持状态栏颜色设置、显示与隐藏

支持本地图片显示

支持GIF图片显示

使用

1.基本使用

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

window = UIWindow.init(frame: UIScreen.main.bounds)
window?.backgroundColor = UIColor.white
let homeVC = ViewController()
let nav = UINavigationController.init(rootViewController: homeVC)
if launchOptions != nil {
/// 通过推送等启动
window?.rootViewController = nav
} else {
/// 正常点击icon启动,加载广告
let adVC = ZLaunchAdVC().adBottom(200).transition(.filpFromLeft).configRootVC(nav)

request(completion: { (url, duration) in
adVC.configNetImage(url: url, duration: duration, adImgViewClick: {
let vc = UIViewController()
vc.view.backgroundColor = UIColor.yellow
homeVC.navigationController?.pushViewController(vc, animated: true)
})
})
window?.rootViewController = adVC
}
window?.makeKeyAndVisible()
return true
}
/// 网络请求
func request(completion: @escaping (_ url: String, _ duration: Int)->()) -> Void {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2, execute: {
let url = "http://chatm-icon.oss-cn-beijing.aliyuncs.com/pic/pic_20170724152928869.gif"
let adDuartion = 8
completion(url, adDuartion)
})
}


2. 默认显示时间、广告图大小、过渡类型 配置

/// defaultDuration: 未设置广告/广告加载不出来时,VC的显示时间,默认3s
/// adViewBottom: 图片距离底部距离,默认100
/// transitionType: 过渡类型,默认fade
let adVC = ZLaunchAdVC(defaultDuration: 3, adViewBottom: 100, transitionType: .filpFromLeft, rootVC: nav)
/// 或者
let adVC = ZLaunchAdVC().adBottom(200).transition(.filpFromLeft).configEnd({
self.window?.rootViewController = nav
})


3. 跳过按钮配置

adVC.configSkipBtn({ (config) in
config.backgroundColor = UIColor.red
config.centerX = 100
config.centerY = 200
config.skipBtnType = .circle
config.strokeColor = UIColor.green
})


4. 加载本地图片

4.1 本地图片

adVC.configLocalImage(image: UIImage(named: "222"), duration: 7, adImgViewClick: {
let vc = UIViewController()
vc.view.backgroundColor = UIColor.yellow
homeVC.navigationController?.pushViewController(vc, animated: true)
})


4.2 本地GIF

adVC.configLocalGif(name: "111", duration: 7, adImgViewClick: {
let vc = UIViewController()
vc.view.backgroundColor = UIColor.yellow
homeVC.navigationController?.pushViewController(vc, animated: true)
})


###### 状态栏设置

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  app启动页广告
相关文章推荐