1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| import UIKit class ZJFunc{ static func delay(delay:Double, closure:@escaping ()->()) { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + delay) { closure(); } } static func async(block:@escaping ()->(),callBack:@escaping()->()){ DispatchQueue(label: NSDate().description).async { block(); DispatchQueue.main.async { callBack(); } } } static func unselectCell(tableView: UITableView)->Void{ delay(delay: 0.1) { if(tableView.indexPathForSelectedRow != nil){ tableView.deselectRow(at: tableView.indexPathForSelectedRow!, animated: true); } } } static func phone(phone:String,viewController:UIViewController)->Void{ let str = "tel:\(phone)"; let callWebView = UIWebView(); viewController.view.addSubview(callWebView); callWebView.loadRequest(URLRequest(url:URL(string:str)!)) } static func msg(phone:String)->Void{ let str = "sms:\(phone)"; UIApplication.shared.openURL(URL(string:str)!); } static func randomNum(num:Int)->Int{ let randomNum = Int(arc4random_uniform(UInt32(num))); return randomNum; } static func scrollViewSpaceToButtom(scrollView: UIScrollView)->CGFloat{ let offset = scrollView.contentOffset; let bounds = scrollView.bounds; let size = scrollView.contentSize; let inset = scrollView.contentInset; let currentOffset = offset.y + bounds.size.height - inset.bottom; let maximumOffset = size.height; let space = maximumOffset-currentOffset; return space; } static func isVersion(version:String)-> Bool{ switch UIDevice.current.systemVersion.compare(version, options: NSString.CompareOptions.numeric) { case .orderedSame, .orderedDescending: return true; case .orderedAscending: return false; } } static func animateView(view: UIView) { let animation = CAKeyframeAnimation() animation.keyPath = "position.x" animation.values = [0, 20, -20, 10, 0] animation.keyTimes = [ NSNumber(value:0), NSNumber(value:1.0 / 6.0), NSNumber(value:3 / 6.0), NSNumber(value:5.0 / 6.0), NSNumber(value:1) ] animation.duration = 0.35 animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut) animation.isAdditive = true view.layer.add(animation, forKey: "shake") } static func animateViewY(view: UIView) { let animation = CAKeyframeAnimation() animation.keyPath = "position.y" animation.values = [0, 10, 0, 5, 0] animation.keyTimes = [ NSNumber(value:0), NSNumber(value:1.0 / 6.0), NSNumber(value:3 / 6.0), NSNumber(value:5.0 / 6.0), NSNumber(value:1) ] animation.duration = 0.35 animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) animation.isAdditive = true view.layer.add(animation, forKey: "shake") } static func animateViewBgColor(view: UIView) { let animation = CABasicAnimation() animation.keyPath = "backgroundColor" animation.fromValue = view.layer.backgroundColor; animation.toValue = UIColor.groupTableViewBackground.cgColor; animation.duration = 0.33 animation.fillMode = kCAFillModeBoth view.layer.add(animation, forKey: nil) let animation2 = CABasicAnimation() animation2.keyPath = "cornerRadius" animation2.fromValue = view.layer.cornerRadius; animation2.toValue = view.frame.width/8; animation2.duration = 0.33 animation2.fillMode = kCAFillModeBoth view.layer.add(animation2, forKey: nil) } }
|