123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- //
- // StartupPageView.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/9/24.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- //
- import UIKit
- import SwiftyMediator
- class StartupPageView: UIView {
-
-
- /// 启动页的模型
- var startupModel : StartupModel?
-
- override init(frame: CGRect) {
- super.init(frame: frame)
- if isNetworkConnect {
- //获取启动视图
- let vc = UIStoryboard(name: "LaunchScreen", bundle: nil)
- .instantiateViewController(withIdentifier: "launch")
- self.addSubview(vc.view)
- UIApplication.shared.windows.last?.addSubview(self)
- configStartupApi()
- }
- }
-
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- lazy var imageView: UIImageView = {
- let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight-40-83-43.5))
- imageView.contentMode = .scaleAspectFill
- imageView.clipsToBounds = true
- imageView.backgroundColor = UIColor.clear
- imageView.isUserInteractionEnabled = true
- imageView.addTapGesture(1, target: self, action: #selector(imageViewAction))
- addSubview(imageView)
- return imageView
- }()
-
-
- lazy var drawCircleProgressButton: DrawCircleProgressButton = {
- let drawCircleProgressButton = DrawCircleProgressButton(frame: CGRect(x: kScreenWidth-20-38, y: kSafeStatusBarHeight, width: 38, height: 38))
- drawCircleProgressButton.setTitle("跳过", for: UIControl.State.normal)
- drawCircleProgressButton.setTitleColor(UIColor.white, for: UIControl.State.normal)
- drawCircleProgressButton.titleLabel?.font = kRegularFont12
- drawCircleProgressButton.trackColor = kThemeColor
- drawCircleProgressButton.progressColor = UIColor.white
- drawCircleProgressButton.fillColor = UIColor(hexString: "000000", alpha: 0.3)
- drawCircleProgressButton.lineWidth = 1.5
- drawCircleProgressButton.addTarget(self, action: #selector(skipAction), for: UIControl.Event.touchUpInside)
- addSubview(drawCircleProgressButton)
- return drawCircleProgressButton
- }()
-
- // 获取数据
- func configStartupApi() {
- SwiftMoyaNetWorkServiceConfig.shared().configStartupApi(completion: {
- [weak self] (startupModel) -> (Void) in
- self?.startupModel = startupModel as? StartupModel
-
- self?.imageView.kf.setImage(with: kURLImage(name: self?.startupModel?.img ?? ""), placeholder: kImage(name: "default_image"), completionHandler: { (result) in
- switch result {
- case .success(_):
- self?.drawCircleProgressButton.startAnimationDuration(3, with: {
- [weak self] in
- self?.skipAction()
- })
- break
- case .failure(_):
- break
- }
- })
- }) { [weak self] (loadingStatus) in
- self?.removeAnimateView()
- }
- }
-
- //跳转H5
- @objc func imageViewAction() {
- if startupModel?.url != "" {
- removeAnimateView()
- Mediator.push(H5RouterModuleType.pushWeb(URLString: startupModel?.url ?? "http://www.uptoyo.com"), animated: true)
- }
- }
-
- //跳过
- @objc func skipAction() {
- removeAnimateView()
- }
-
- // 移除动画
- func removeAnimateView() {
- //播放动画效果,完毕后将其移除
- UIView.animate(withDuration: 1, delay: 0, options: .beginFromCurrentState, animations: {
- [weak self] in
- self?.alpha = 0.0
- let transform = CATransform3DScale(CATransform3DIdentity, 1.5, 1.5, 1.0)
- self?.layer.transform = transform
- }) { [weak self] (finished) in
- self?.removeFromSuperview()
- }
- }
-
- class func startupPageView() {
- _ = StartupPageView.init(frame: UIScreen.main.bounds)
- }
- }
|