Commit a8d54916 authored by lujunye's avatar lujunye

添加swiftNotice

parent 4f67617f
......@@ -27,6 +27,8 @@
E09B03C02445B96500211A51 /* FgPassViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E09B03BE2445B96500211A51 /* FgPassViewController.swift */; };
E09B03C12445B96500211A51 /* FgPassViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E09B03BF2445B96500211A51 /* FgPassViewController.xib */; };
E09B03C32445BD9500211A51 /* NavViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E09B03C22445BD9500211A51 /* NavViewController.swift */; };
E09B03C62445BF6700211A51 /* NavBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E09B03C52445BF6700211A51 /* NavBarView.swift */; };
E09B03C82445BF9300211A51 /* SwiftNotice.swift in Sources */ = {isa = PBXBuildFile; fileRef = E09B03C72445BF9300211A51 /* SwiftNotice.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
......@@ -75,6 +77,8 @@
E09B03BE2445B96500211A51 /* FgPassViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FgPassViewController.swift; sourceTree = "<group>"; };
E09B03BF2445B96500211A51 /* FgPassViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = FgPassViewController.xib; sourceTree = "<group>"; };
E09B03C22445BD9500211A51 /* NavViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavViewController.swift; sourceTree = "<group>"; };
E09B03C52445BF6700211A51 /* NavBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavBarView.swift; sourceTree = "<group>"; };
E09B03C72445BF9300211A51 /* SwiftNotice.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftNotice.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -198,6 +202,7 @@
E09B039F2445AF4D00211A51 /* Define */ = {
isa = PBXGroup;
children = (
E09B03C72445BF9300211A51 /* SwiftNotice.swift */,
E09B03A22445AF9500211A51 /* NetworkRequest.swift */,
E09B03A02445AF7100211A51 /* Define.swift */,
);
......@@ -225,6 +230,7 @@
E09B03AC2445B0B200211A51 /* View */ = {
isa = PBXGroup;
children = (
E09B03C42445BF4600211A51 /* NavBarView */,
);
path = View;
sourceTree = "<group>";
......@@ -273,6 +279,14 @@
path = "忘记密码";
sourceTree = "<group>";
};
E09B03C42445BF4600211A51 /* NavBarView */ = {
isa = PBXGroup;
children = (
E09B03C52445BF6700211A51 /* NavBarView.swift */,
);
path = NavBarView;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
......@@ -455,11 +469,13 @@
E09B03B62445B85A00211A51 /* LoginViewController.swift in Sources */,
E09B03C32445BD9500211A51 /* NavViewController.swift in Sources */,
E00D85DF244561FD00F5F816 /* AppDelegate.swift in Sources */,
E09B03C62445BF6700211A51 /* NavBarView.swift in Sources */,
E00D85E1244561FD00F5F816 /* SceneDelegate.swift in Sources */,
E09B03A12445AF7100211A51 /* Define.swift in Sources */,
E09B03A82445B04E00211A51 /* BaseView.swift in Sources */,
E09B03C02445B96500211A51 /* FgPassViewController.swift in Sources */,
E09B03AB2445B0A300211A51 /* LoginModel.swift in Sources */,
E09B03C82445BF9300211A51 /* SwiftNotice.swift in Sources */,
E09B03A32445AF9500211A51 /* NetworkRequest.swift in Sources */,
E09B03A72445B04E00211A51 /* BaseViewController.swift in Sources */,
);
......
......@@ -112,7 +112,7 @@ extension NetworkRequest {
case .success(let value):
let json = JSON(value)
print(json)
//SwiftNotice.clear()
SwiftNotice.clear()
if json["code"].intValue == 200 {
success(Mapper<T>().map(JSONObject: value))
......@@ -128,7 +128,7 @@ extension NetworkRequest {
failture(DogError.DataInvalidError)
}
case .failure(let error):
//SwiftNotice.clear()
SwiftNotice.clear()
let alt = UIAlertView(title: "提示", message: "网络错误", delegate: nil, cancelButtonTitle: "确定")
......@@ -196,7 +196,7 @@ extension NetworkRequest {
case .success(let value):
let json = JSON(value)
print(json)
//SwiftNotice.clear()
SwiftNotice.clear()
UserDefaults.standard.setValue(json["message"].stringValue, forKey: "jsonMessage")
......@@ -216,7 +216,7 @@ extension NetworkRequest {
}
}
case .failure(let error):
//SwiftNotice.clear()
SwiftNotice.clear()
failture(error)
}
}
......
//
// SwiftNotice.swift
// SwiftNotice
//
// Created by JohnLui on 15/4/15.
// Copyright (c) 2015年 com.lvwenhan. All rights reserved.
//
import Foundation
import UIKit
private let sn_topBar: Int = 1001
extension UIResponder {
/// wait with your own animated images
@discardableResult
func pleaseWaitWithImages(_ imageNames: Array<UIImage>, timeInterval: Int) -> UIWindow{
return SwiftNotice.wait(imageNames, timeInterval: timeInterval)
}
// api changed from v3.3
@discardableResult
func noticeTop(_ text: String, autoClear: Bool = true, autoClearTime: Int = 1) -> UIWindow{
return SwiftNotice.noticeOnStatusBar(text, autoClear: autoClear, autoClearTime: autoClearTime)
}
// new apis from v3.3
@discardableResult
func noticeSuccess(_ text: String, autoClear: Bool = false, autoClearTime: Int = 3) -> UIWindow{
return SwiftNotice.showNoticeWithText(NoticeType.success, text: text, autoClear: autoClear, autoClearTime: autoClearTime)
}
@discardableResult
func noticeError(_ text: String, autoClear: Bool = false, autoClearTime: Int = 3) -> UIWindow{
return SwiftNotice.showNoticeWithText(NoticeType.error, text: text, autoClear: autoClear, autoClearTime: autoClearTime)
}
@discardableResult
func noticeInfo(_ text: String, autoClear: Bool = false, autoClearTime: Int = 3) -> UIWindow{
return SwiftNotice.showNoticeWithText(NoticeType.info, text: text, autoClear: autoClear, autoClearTime: autoClearTime)
}
// old apis
@discardableResult
func successNotice(_ text: String, autoClear: Bool = true) -> UIWindow{
return SwiftNotice.showNoticeWithText(NoticeType.success, text: text, autoClear: autoClear, autoClearTime: 3)
}
@discardableResult
func errorNotice(_ text: String, autoClear: Bool = true) -> UIWindow{
return SwiftNotice.showNoticeWithText(NoticeType.error, text: text, autoClear: autoClear, autoClearTime: 3)
}
@discardableResult
func infoNotice(_ text: String, autoClear: Bool = true) -> UIWindow{
return SwiftNotice.showNoticeWithText(NoticeType.info, text: text, autoClear: autoClear, autoClearTime: 3)
}
@discardableResult
func notice(_ text: String, type: NoticeType, autoClear: Bool, autoClearTime: Int = 3) -> UIWindow{
return SwiftNotice.showNoticeWithText(type, text: text, autoClear: autoClear, autoClearTime: autoClearTime)
}
@discardableResult
func pleaseWait() -> UIWindow{
return SwiftNotice.wait()
}
@discardableResult
func noticeOnlyText(_ text: String) -> UIWindow{
return SwiftNotice.showText(text)
}
func clearAllNotice() {
SwiftNotice.clear()
}
}
enum NoticeType{
case success
case error
case info
}
class SwiftNotice: NSObject {
static var windows = Array<UIWindow?>()
static let rv = UIApplication.shared.keyWindow?.subviews.first as UIView?
static var timer: DispatchSource!
static var timerTimes = 0
/* just for iOS 8
*/
static var degree: Double {
get {
return [0, 0, 180, 270, 90][UIApplication.shared.statusBarOrientation.hashValue] as Double
}
}
// fix https://github.com/johnlui/SwiftNotice/issues/2
// thanks broccolii(https://github.com/broccolii) and his PR https://github.com/johnlui/SwiftNotice/pull/5
static func clear() {
self.cancelPreviousPerformRequests(withTarget: self)
if let _ = timer {
timer.cancel()
timer = nil
timerTimes = 0
}
windows.removeAll(keepingCapacity: false)
}
@discardableResult
static func noticeOnStatusBar(_ text: String, autoClear: Bool, autoClearTime: Int) -> UIWindow{
let frame = UIApplication.shared.statusBarFrame
let window = UIWindow()
window.backgroundColor = UIColor.clear
let view = UIView()
view.backgroundColor = UIColor(red: 0x6a/0x100, green: 0xb4/0x100, blue: 0x9f/0x100, alpha: 1)
let label = UILabel(frame: frame.height > 20 ? CGRect(x: frame.origin.x, y: frame.origin.y + frame.height - 17, width: frame.width, height: 20) : frame)
label.textAlignment = NSTextAlignment.center
label.font = UIFont.systemFont(ofSize: 12)
label.textColor = UIColor.white
label.text = text
view.addSubview(label)
window.frame = frame
view.frame = frame
if let version = Double(UIDevice.current.systemVersion),
version < 9.0 {
// change center
var array = [UIScreen.main.bounds.width, UIScreen.main.bounds.height]
array = array.sorted(by: <)
let screenWidth = array[0]
let screenHeight = array[1]
let x = [0, screenWidth/2, screenWidth/2, 10, screenWidth-10][UIApplication.shared.statusBarOrientation.hashValue] as CGFloat
let y = [0, 10, screenHeight-10, screenHeight/2, screenHeight/2][UIApplication.shared.statusBarOrientation.hashValue] as CGFloat
window.center = CGPoint(x: x, y: y)
// change direction
window.transform = CGAffineTransform(rotationAngle: CGFloat(degree * Double.pi / 180))
}
window.windowLevel = UIWindow.Level.statusBar
window.isHidden = false
window.addSubview(view)
windows.append(window)
var origPoint = view.frame.origin
origPoint.y = -(view.frame.size.height)
let destPoint = view.frame.origin
view.tag = sn_topBar
view.frame = CGRect(origin: origPoint, size: view.frame.size)
UIView.animate(withDuration: 0.3, animations: {
view.frame = CGRect(origin: destPoint, size: view.frame.size)
}, completion: { b in
if autoClear {
self.perform(.hideNotice, with: window, afterDelay: TimeInterval(autoClearTime))
}
})
return window
}
@discardableResult
static func wait(_ imageNames: Array<UIImage> = Array<UIImage>(), timeInterval: Int = 0) -> UIWindow {
let frame = CGRect(x: 0, y: 0, width: 78, height: 78)
let window = UIWindow()
window.backgroundColor = UIColor.clear
let mainView = UIView()
mainView.layer.cornerRadius = 12
mainView.backgroundColor = UIColor(red:0, green:0, blue:0, alpha: 0.8)
if imageNames.count > 0 {
if imageNames.count > timerTimes {
let iv = UIImageView(frame: frame)
iv.image = imageNames.first!
iv.contentMode = UIView.ContentMode.scaleAspectFit
mainView.addSubview(iv)
timer = DispatchSource.makeTimerSource(flags: DispatchSource.TimerFlags(rawValue: UInt(0)), queue: DispatchQueue.main) as! DispatchSource
timer.schedule(deadline: DispatchTime.now(), repeating: DispatchTimeInterval.milliseconds(timeInterval))
timer.setEventHandler(handler: { () -> Void in
let name = imageNames[timerTimes % imageNames.count]
iv.image = name
timerTimes += 1
})
timer.resume()
}
} else {
let ai = UIActivityIndicatorView(style: UIActivityIndicatorView.Style.whiteLarge)
ai.frame = CGRect(x: 21, y: 21, width: 36, height: 36)
ai.startAnimating()
mainView.addSubview(ai)
}
window.frame = frame
mainView.frame = frame
window.center = rv!.center
if let version = Double(UIDevice.current.systemVersion),
version < 9.0 {
// change center
window.center = getRealCenter()
// change direction
window.transform = CGAffineTransform(rotationAngle: CGFloat(degree * Double.pi / 180))
}
window.windowLevel = UIWindow.Level.alert
window.isHidden = false
window.addSubview(mainView)
windows.append(window)
mainView.alpha = 0.0
UIView.animate(withDuration: 0.2, animations: {
mainView.alpha = 1
})
return window
}
@discardableResult
static func showText(_ text: String, autoClear: Bool=true, autoClearTime: Int=2) -> UIWindow {
let window = UIWindow()
window.backgroundColor = UIColor.clear
let mainView = UIView()
mainView.layer.cornerRadius = 12
mainView.backgroundColor = UIColor(red:0, green:0, blue:0, alpha: 0.8)
let label = UILabel()
label.text = text
label.numberOfLines = 0
label.font = UIFont.systemFont(ofSize: 13)
label.textAlignment = NSTextAlignment.center
label.textColor = UIColor.white
let size = label.sizeThatFits(CGSize(width: UIScreen.main.bounds.width-82, height: CGFloat.greatestFiniteMagnitude))
label.bounds = CGRect(x: 0, y: 0, width: size.width, height: size.height)
mainView.addSubview(label)
let superFrame = CGRect(x: 0, y: 0, width: label.frame.width + 50 , height: label.frame.height + 30)
window.frame = superFrame
mainView.frame = superFrame
label.center = mainView.center
window.center = rv!.center
if let version = Double(UIDevice.current.systemVersion),
version < 9.0 {
// change center
window.center = getRealCenter()
// change direction
window.transform = CGAffineTransform(rotationAngle: CGFloat(degree * Double.pi / 180))
}
window.windowLevel = UIWindow.Level.alert
window.isHidden = false
window.addSubview(mainView)
windows.append(window)
if autoClear {
self.perform(.hideNotice, with: window, afterDelay: TimeInterval(autoClearTime))
}
return window
}
@discardableResult
static func showNoticeWithText(_ type: NoticeType,text: String, autoClear: Bool, autoClearTime: Int) -> UIWindow {
let frame = CGRect(x: 0, y: 0, width: 90, height: 90)
let window = UIWindow()
window.backgroundColor = UIColor.clear
let mainView = UIView()
mainView.layer.cornerRadius = 10
mainView.backgroundColor = UIColor(red:0, green:0, blue:0, alpha: 0.7)
var image = UIImage()
switch type {
case .success:
image = SwiftNoticeSDK.imageOfCheckmark
case .error:
image = SwiftNoticeSDK.imageOfCross
case .info:
image = SwiftNoticeSDK.imageOfInfo
}
let checkmarkView = UIImageView(image: image)
checkmarkView.frame = CGRect(x: 27, y: 15, width: 36, height: 36)
mainView.addSubview(checkmarkView)
let label = UILabel(frame: CGRect(x: 0, y: 60, width: 90, height: 16))
label.font = UIFont.systemFont(ofSize: 13)
label.textColor = UIColor.white
label.text = text
label.textAlignment = NSTextAlignment.center
mainView.addSubview(label)
window.frame = frame
mainView.frame = frame
window.center = rv!.center
if let version = Double(UIDevice.current.systemVersion),
version < 9.0 {
// change center
window.center = getRealCenter()
// change direction
window.transform = CGAffineTransform(rotationAngle: CGFloat(degree * Double.pi / 180))
}
window.windowLevel = UIWindow.Level.alert
window.center = rv!.center
window.isHidden = false
window.addSubview(mainView)
windows.append(window)
mainView.alpha = 0.0
UIView.animate(withDuration: 0.2, animations: {
mainView.alpha = 1
})
if autoClear {
self.perform(.hideNotice, with: window, afterDelay: TimeInterval(autoClearTime))
}
return window
}
// just for iOS 8
static func getRealCenter() -> CGPoint {
if UIApplication.shared.statusBarOrientation.hashValue >= 3 {
return CGPoint(x: rv!.center.y, y: rv!.center.x)
} else {
return rv!.center
}
}
}
class SwiftNoticeSDK {
struct Cache {
static var imageOfCheckmark: UIImage?
static var imageOfCross: UIImage?
static var imageOfInfo: UIImage?
}
class func draw(_ type: NoticeType) {
let checkmarkShapePath = UIBezierPath()
// draw circle
checkmarkShapePath.move(to: CGPoint(x: 36, y: 18))
checkmarkShapePath.addArc(withCenter: CGPoint(x: 18, y: 18), radius: 17.5, startAngle: 0, endAngle: CGFloat(Double.pi*2), clockwise: true)
checkmarkShapePath.close()
switch type {
case .success: // draw checkmark
checkmarkShapePath.move(to: CGPoint(x: 10, y: 18))
checkmarkShapePath.addLine(to: CGPoint(x: 16, y: 24))
checkmarkShapePath.addLine(to: CGPoint(x: 27, y: 13))
checkmarkShapePath.move(to: CGPoint(x: 10, y: 18))
checkmarkShapePath.close()
case .error: // draw X
checkmarkShapePath.move(to: CGPoint(x: 10, y: 10))
checkmarkShapePath.addLine(to: CGPoint(x: 26, y: 26))
checkmarkShapePath.move(to: CGPoint(x: 10, y: 26))
checkmarkShapePath.addLine(to: CGPoint(x: 26, y: 10))
checkmarkShapePath.move(to: CGPoint(x: 10, y: 10))
checkmarkShapePath.close()
case .info:
checkmarkShapePath.move(to: CGPoint(x: 18, y: 6))
checkmarkShapePath.addLine(to: CGPoint(x: 18, y: 22))
checkmarkShapePath.move(to: CGPoint(x: 18, y: 6))
checkmarkShapePath.close()
UIColor.white.setStroke()
checkmarkShapePath.stroke()
let checkmarkShapePath = UIBezierPath()
checkmarkShapePath.move(to: CGPoint(x: 18, y: 27))
checkmarkShapePath.addArc(withCenter: CGPoint(x: 18, y: 27), radius: 1, startAngle: 0, endAngle: CGFloat(Double.pi*2), clockwise: true)
checkmarkShapePath.close()
UIColor.white.setFill()
checkmarkShapePath.fill()
}
UIColor.white.setStroke()
checkmarkShapePath.stroke()
}
class var imageOfCheckmark: UIImage {
if (Cache.imageOfCheckmark != nil) {
return Cache.imageOfCheckmark!
}
UIGraphicsBeginImageContextWithOptions(CGSize(width: 36, height: 36), false, 0)
SwiftNoticeSDK.draw(NoticeType.success)
Cache.imageOfCheckmark = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return Cache.imageOfCheckmark!
}
class var imageOfCross: UIImage {
if (Cache.imageOfCross != nil) {
return Cache.imageOfCross!
}
UIGraphicsBeginImageContextWithOptions(CGSize(width: 36, height: 36), false, 0)
SwiftNoticeSDK.draw(NoticeType.error)
Cache.imageOfCross = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return Cache.imageOfCross!
}
class var imageOfInfo: UIImage {
if (Cache.imageOfInfo != nil) {
return Cache.imageOfInfo!
}
UIGraphicsBeginImageContextWithOptions(CGSize(width: 36, height: 36), false, 0)
SwiftNoticeSDK.draw(NoticeType.info)
Cache.imageOfInfo = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return Cache.imageOfInfo!
}
}
extension UIWindow{
func hide(){
SwiftNotice.hideNotice(self)
}
}
fileprivate extension Selector {
static let hideNotice = #selector(SwiftNotice.hideNotice(_:))
}
@objc extension SwiftNotice {
// fix https://github.com/johnlui/SwiftNotice/issues/2
static func hideNotice(_ sender: AnyObject) {
if let window = sender as? UIWindow {
if let v = window.subviews.first {
UIView.animate(withDuration: 0.2, animations: {
if v.tag == sn_topBar {
v.frame = CGRect(x: 0, y: -v.frame.height, width: v.frame.width, height: v.frame.height)
}
v.alpha = 0
}, completion: { b in
if let index = windows.index(where: { (item) -> Bool in
return item == window
}) {
windows.remove(at: index)
}
})
}
}
}
}
//
// NavBarView.swift
// GeLiLaiGeWan
//
// Created by geli on 2018/7/20.
// Copyright © 2018年 geli. All rights reserved.
//
import UIKit
@objc protocol NavBarViewDelegate {
@objc optional func backAction()
@objc optional func rightBtnClick()
}
class NavBarView: BaseView {
var deleagte:NavBarViewDelegate?
var title:String?{
didSet{
titleLbl.text = title
}
}
var rightImg:UIImage?{
didSet{
rightBtn.setImage(rightImg, for: .normal)
rightBtn.snp.makeConstraints { (make) in
make.right.equalTo(-12)
make.bottom.equalTo(-14)
}
}
}
var rightTitle:String?{
didSet{
rightBtn.setTitle(rightTitle, for: .normal)
rightBtn.titleLabel?.font = setFont(15)
rightBtn.sizeToFit()
rightBtn.setTitleColor(UIColor.black, for: UIControlState(rawValue: 0))
rightBtn.snp.makeConstraints { (make) in
make.right.equalTo(-12)
make.bottom.equalTo(-14)
}
}
}
var leftImg:UIImage?{
didSet{
leftImgV.image = leftImg
}
}
var leftTitle:String?{
didSet{
leftBtn.setTitle(leftTitle, for: .normal)
leftBtn.sizeToFit()
leftBtn.snp.makeConstraints { (make) in
make.left.equalTo(12)
make.bottom.equalTo(-14)
}
}
}
var lineView:UIView!
var leftImgV:UIImageView!
var titleLbl:UILabel!
private
var rightBtn:UIButton!
var leftBtn:UIButton!
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = UIColor.white
titleLbl = UILabel()
titleLbl.font = setFont(18)
titleLbl.textAlignment = .center
self.addSubview(titleLbl)
titleLbl.snp.makeConstraints { (make) in
make.bottom.left.right.equalToSuperview()
make.height.equalTo(44)
}
leftImgV = UIImageView()
leftImgV.image = UIImage(named: "icon_fanhui")
self.addSubview(leftImgV)
leftImgV.snp.makeConstraints { (make) in
make.left.equalTo(12)
make.bottom.equalTo(-14)
make.width.equalTo(10)
make.height.equalTo(17)
}
leftBtn = UIButton(frame: CGRect(x: 0, y: 0, width: 60, height: frame.size.height))
leftBtn.addTarget(self, action: #selector(backAction), for: .touchUpInside)
self.addSubview(leftBtn)
rightBtn = UIButton()
rightBtn.addTarget(self, action: #selector(rightClick), for: .touchUpInside)
self.addSubview(rightBtn)
lineView = UIView(frame: CGRect(x: 0, y: frame.size.height-1, width: frame.size.width, height: 1))
lineView.backgroundColor = RGB(r: 244, g: 244, b: 244)
self.addSubview(lineView)
}
@objc func backAction(){
deleagte?.backAction!()
if leftImgV.isHidden == false {
self.superview?.inputViewController?.navigationController?.popViewController(animated: true)
}
}
@objc func rightClick(){
deleagte?.rightBtnClick!()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
......@@ -21,4 +21,5 @@ pod 'Dollar'
pod 'ViewAnimator'
pod 'SkeletonView'
pod 'RealmSwift'
pod 'SnapKit'
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment