Нет описания

CommonFunctions.swift 1.6KB

    // // CommonFunctions.swift // PaiAi // // Created by mac on 16/7/21. // Copyright © 2016年 FFIB. All rights reserved. // import ObjectMapper let onePixel: CGFloat = 1 / UIScreen.main.scale var AppRootController: UIViewController { get { let ctl = UIApplication.shared.delegate?.window??.rootViewController return ctl! } } var AppRootWindow: UIWindow? { get { return UIApplication.shared.keyWindow } } var AppRootView: UIView { get { guard let view = UIApplication.shared.delegate?.window??.rootViewController?.view else { return UIView() } return view } } func GetParentCell(_ view: UIView) -> UITableViewCell? { var parent = view.superview while parent != nil { if let p = parent as? UITableViewCell { return p } parent = parent?.superview } return nil } func GetParentCollectionCell(_ view: UIView) -> UICollectionViewCell? { var parent = view.superview while parent != nil { if let p = parent as? UICollectionViewCell { return p } parent = parent?.superview } return nil } func Delay(_ time: TimeInterval, queue: DispatchQueue = DispatchQueue.main, block :@escaping () -> Void) { queue.asyncAfter(deadline: DispatchTime.now() + Double(Int64(time*TimeInterval(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: block) } func RGBAColor(_ r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat = 1) -> UIColor { return UIColor(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: a) } extension Mappable { mutating func mapping(map: Map) { } }