/// 获得当前窗口
var JY_WINDOW: UIWindow? {
get{
if let app = UIApplication.shared.delegate as? AppDelegate {
return app.window
}
return nil
}
}

  

//iPhoneX系列
var iphoneX_Series: Bool {
get { if UIDevice.current.userInterfaceIdiom != UIUserInterfaceIdiom.phone{
debugPrint("不是iPhone, 是 \(UIDevice.current.userInterfaceIdiom.rawValue)")
} if #available(iOS 11.0, *) {
if let bottom = JY_WINDOW?.safeAreaInsets.bottom , bottom > 0 {
return true
}
} else {
debugPrint("iOS11 之前的版本")
}
return false
}
}

  

在iOS11以后的 非iPhoneX系列, 安全区高度是电池蓝高度,一般 获取安全区高度:在非iPhoneX系列 上以 Y = 0 开始,

var JY_NAV_HEIGHT : CGFloat{
get{
if #available(iOS 11.0, *) , iphoneX_Series{
let safeTopHeight = JY_WINDOW?.safeAreaInsets.top ?? 0
return safeTopHeight
}
return 0
}
}

  

一些基础配置

///获取APP名称
let JY_APP_NAME = Bundle.main.infoDictionary?["CFBundleDisplayName"] as? String ?? "" ///获取APP版本号
let JY_APP_VERSION = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
/// 获取手机版本号
let iPhoneSystemVersion: String = UIDevice.current.systemVersion /// 手机机型
var iPhoneModel: String {
get {
var systemInfo = utsname()
uname(&systemInfo)
let platform = withUnsafePointer(to: &systemInfo.machine.0) { ptr in
return String(cString: ptr)
}
return platform
}
} //FIXME:屏幕宽度
let JY_DEVICE_HEIGHT = (UIScreen.main.bounds.size.height) //FIXME:屏幕高度
let JY_DEVICE_WIDTH = (UIScreen.main.bounds.size.width) //FIXME: 判断是不是运行在模拟器上面
struct Platform {
static let isSimulator: Bool = {
var isSim = false
#if arch(i386) || arch(x86_64)
isSim = true
#endif
return isSim
}()
} //自适应宽高:6S位基准
func fit(_ value:CGFloat) -> CGFloat {
return value * (JY_DEVICE_WIDTH < JY_DEVICE_HEIGHT ? JY_DEVICE_WIDTH:JY_DEVICE_HEIGHT ) / 375
} //FIXME: 简写获取nib
func GetStoryboardVC(storyboardName:String!,vcName:String!) -> UIViewController {
let storeboard:UIStoryboard! = UIStoryboard.init(name: storyboardName, bundle: nil)
let vc = storeboard.instantiateViewController(withIdentifier: vcName)
return vc
}
//FIXME: 自定义debug 模式下不打印
func DDLOG<Message>(message: Message,
fileName: String = #file,
methodName: String = #function,
lineNumber: Int = #line){
#if DEBUG
print("\((fileName as NSString).pathComponents.last!).\(methodName)[\(lineNumber)]:\(message)")
#endif
}

  

 

获取当前显示的VC

extension UIViewController {

    /// 设置controller的导航标题
///
/// - Parameter title: 标题
func setNavigationTitleViewTitle(title: String , textColor: UIColor = UIColor.white) {
let titleLab = JYBaseViewModel.creatLabe(text: title, font: UIFont.systemFont(ofSize: 22, weight: .medium), textColor: textColor , textAlignment: .center)
titleLab.translatesAutoresizingMaskIntoConstraints = true
titleLab.bounds = CGRect(x: 0, y: 0, width: 150, height: 44)
self.navigationItem.titleView = titleLab
} /// 设置导航返回item(controller必须存在导航控制器)
///
/// - Parameter action: 返回的响应事件
func setNavigationLeftBackItem(action: Selector? = nil, imageName:String = "dateBack") {
let backBtn = UIButton(fontSize: 17, isSetBoldFontSize: true, textColor: UIColor.init(hexColor: "4A4A4A"), titleStr: "返回", self, action: action, for: .touchUpInside)
backBtn.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: UIFont.Weight.medium)
// openorder_back_picture
backBtn.setImage(UIImage.init(named: imageName)?.scaledToSize(newSize: CGSize(width: 12, height: 20), withScale: false), for: UIControl.State.normal)
backBtn.bounds = CGRect(origin: CGPoint(x: 0, y: 0), size: backBtn.intrinsicContentSize)
backBtn.backgroundColor = UIColor.clear
backBtn.translatesAutoresizingMaskIntoConstraints = true
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: backBtn)
} /// 获取当前显示的VC
///
/// - Returns: 当前屏幕显示的VC
class func getCurrentViewController() -> UIViewController?{
// 获取当先显示的window
var currentWindow = UIApplication.shared.keyWindow ?? UIWindow()
if currentWindow.windowLevel != UIWindow.Level.normal {
let windowArr = UIApplication.shared.windows
for window in windowArr {
if window.windowLevel == UIWindow.Level.normal {
currentWindow = window
break
}
}
}
return UIViewController.getNextXController(nextController: currentWindow.rootViewController)
} //
private class func getNextXController(nextController: UIViewController?) -> UIViewController? {
if nextController == nil {
return nil
}else if nextController?.presentedViewController != nil {
return UIViewController.getNextXController(nextController: nextController?.presentedViewController)
}else if let tabbar = nextController as? UITabBarController {
return UIViewController.getNextXController(nextController: tabbar.selectedViewController)
}else if let nav = nextController as? UINavigationController {
return UIViewController.getNextXController(nextController: nav.visibleViewController)
}
return nextController
}
}

  

iOS - iphoneX系列 - 全局配置的基本信息的更多相关文章

  1. Apache系列:Apache的全局配置

    配置文件组成: 整个配置文件由3段组成: (1)全局配置:对主服务器或虚拟机都有效,且有些功能是服务器自身工作属性: (2)主服务器:主站属性: (3)虚拟主机:虚拟主机及属性定义 注:第二段和第三段 ...

  2. iOS iPhoneX/iPhoneXS/iPhoneXR/iPhoneXS Max系列适配

    以前异性屏只有一款iPhoneX,所以在适配的时候直接判断高度是否等于812即可判断是否是iPhoneX #define IS_IPHONE_X (IS_IPHONE && SCREE ...

  3. iOS开发系列--通知与消息机制

    概述 在多数移动应用中任何时候都只能有一个应用程序处于活跃状态,如果其他应用此刻发生了一些用户感兴趣的那么通过通知机制就可以告诉用户此时发生的事情.iOS中通知机制又叫消息机制,其包括两类:一类是本地 ...

  4. iOS开发系列--数据存取

    概览 在iOS开发中数据存储的方式可以归纳为两类:一类是存储为文件,另一类是存储到数据库.例如前面IOS开发系列-Objective-C之Foundation框架的文章中提到归档.plist文件存储, ...

  5. iOS开发系列--网络开发

    概览 大部分应用程序都或多或少会牵扯到网络开发,例如说新浪微博.微信等,这些应用本身可能采用iOS开发,但是所有的数据支撑都是基于后台网络服务器的.如今,网络编程越来越普遍,孤立的应用通常是没有生命力 ...

  6. 【转】iOS开发系列--数据存取

    原文: http://www.cnblogs.com/kenshincui/p/4077833.html#SQLite 概览 在iOS开发中数据存储的方式可以归纳为两类:一类是存储为文件,另一类是存储 ...

  7. iOS开发系列--通知与消息机制--转

    来自:http://www.cocoachina.com/ios/20150318/11364.html 概述 在多数移动应用中任何时候都只能有一个应用程序处于活跃状态,如果其他应用此刻发生了一些用户 ...

  8. iOS开发系列--Swift语言

    概述 Swift是苹果2014年推出的全新的编程语言,它继承了C语言.ObjC的特性,且克服了C语言的兼容性问题.Swift发展过程中不仅保留了ObjC很多语法特性,它也借鉴了多种现代化语言的特点,在 ...

  9. iOS开发系列--App扩展开发

    概述 从iOS 8 开始Apple引入了扩展(Extension)用于增强系统应用服务和应用之间的交互.它的出现让自定义键盘.系统分享集成等这些依靠系统服务的开发变成了可能.WWDC 2016上众多更 ...

随机推荐

  1. cordova-config.xml 配置记录

    <?xml version='1.0' encoding='utf-8'?> <widget id="come.gs.webapp1" version=" ...

  2. ACM__并查集

    并查集是树型的数据结构,处理不想交集合 主要解决查找和合并的问题 步骤: 初始化 把每个点所在的集合初始化为自身 复杂度为O(N) 查找 查找元素所在的集合,即根节点 合并 将两个元素所在的集合合并在 ...

  3. Linux主机如何用ssh去登录docker容器的步骤

    进入终端,sudo -i,切换root,输入docker -d 打开另一个终端,切换root,输入docker search ubuntu,大概如下结果: NAME                   ...

  4. 367. Valid Perfect Square

    原题: 367. Valid Perfect Square 读题: 求一个整数是否为完全平方数,如1,4,9,16,……就是完全平方数,这题主要是运算效率问题 求解方法1:812ms class So ...

  5. mongodb的优缺点

    在这里收集下我自己对Mongodb的一些优缺点方面的认识,或者是通过其它比较可靠的网文上引用或者摘录的作为依据,这个是一个渐进的过程,也是随着我对Mongodb认识的加深而不断扩展的. (1)Mong ...

  6. mysql 回顾

    主键可以是一个或者是多个列,但所有的列(或者是列的组合)必须是唯一的,非空的 关键字distinct 可以去重,实现该效果还可以使用group by limit 默认从 0 开始,limit 5 其实 ...

  7. ArcGIS特殊标注效果的简单实现

    1. 普通纯色背景:例如望仙亭,水垄沟: 方法:   2. 背景+边框 例如进入点 方法:    

  8. sublime text3 激活码——许可证

    亲测: 现在是公元2018年6月4日.晴 ``` ----- BEGIN LICENSE ----- sgbteam Single User License EA7E-1153259 8891CBB9 ...

  9. 利用原生态的(System.Web.Extensions)JavaScriptSerializer将mvc 前台提交到controller序列化复杂对象

    主要代码如下: public JsonResult Test() { string s = Request.Form.ToString(); JavaScriptSerializer jss = ne ...

  10. MongoDB应用场景

    数据记录如下 /* 1 */ { "_id" : ObjectId("5b56dd19a171d7e9bfb03ac1"), "name" ...