//
|
// YYAlertNoneViewController.swift
|
// FollowMeProject
|
//
|
// Created by alvin_y on 2020/8/21.
|
// Copyright © 2020 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
import RxCocoa
|
import RxSwift
|
|
class YYAlertNoneViewController: YYViewController {
|
|
|
/// 内容
|
@IBOutlet weak var label_content: UILabel!
|
|
var duration: Int = 2
|
|
var textFieldText: String?
|
var isAutoDismiss: Bool = true
|
var onDone: onDoneBlock?
|
var backgroundColor: UIColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0)
|
|
init (){
|
super.init(nibName: String(describing: YYAlertNoneViewController.self), bundle: Bundle.main)
|
modalTransitionStyle = .crossDissolve
|
modalPresentationStyle = .overFullScreen
|
|
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
|
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
// Do any additional setup after loading the view.
|
view.backgroundColor = backgroundColor
|
label_content.text = textFieldText
|
|
Observable<Int>.interval(RxTimeInterval.seconds(1), scheduler: MainScheduler.instance)
|
.subscribe(onNext: {[unowned self] (sec) in
|
if sec >= self.duration{
|
self.dismiss(animated: true, completion: nil)
|
self.onDone?()
|
}
|
})
|
.disposed(by: disposeBag)
|
}
|
|
|
class func display(text: String?,duration: Int = 2,backgroundColor: UIColor = .clear,onDone: @escaping () -> Void) {
|
let vc = YYAlertNoneViewController()
|
vc.textFieldText = text
|
vc.backgroundColor = backgroundColor
|
vc.onDone = onDone
|
vc.duration = duration
|
self.base()?.present(vc, animated: true, completion: nil)
|
}
|
|
|
}
|