/// 获得当前窗口
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. MySQL null与not null和null与空值''的区别

    参考连接:https://segmentfault.com/a/1190000009540449 相信很多用了MySQL很久的人,对这两个字段属性的概念还不是很清楚,一般会有以下疑问: 我字段类型是n ...

  2. mysql主从复制搭建中几种log和pos详解

    一.主从原理 Replication 线程   Mysql的 Replication 是一个异步的复制过程,从一个 Mysql instace(我们称之为 Master)复制到另一个 Mysql in ...

  3. python 学习笔记之@property

    今天学习python类看到 @property 的用法觉得很新奇,就自己尝试了很久,刚开始不明白,后来终于明白了点 其实总结一句话就是, @property 把类中的方法调用方式改变成当成属性属性调用 ...

  4. NGINX安全

    http://anyun.org/a/jishuguanzhu/WEBjishu/2017/0804/8721.html

  5. 显卡安装一直循环在登录界面——解决之-T450安装显卡驱动和cuda7.5发现的一些问题

    今天,在笔记本T450上,要装zed双目相机的驱动,需要显卡模块和cuda7.5,使用了三种方式,才成功. 1.使用 sudo ubuntu-drivers devices 来查看显卡支持驱动版本,因 ...

  6. 如何跟踪某个session的SQL

    1 oracle自带的sql trace程序可以跟踪本地session sys: alter system set sql_trace = true;对所有会话跟踪 schema: alter ses ...

  7. linux安装node简单方法

    1.去官网下载和自己系统匹配的文件: 英文网址:https://nodejs.org/en/download/ 中文网址:http://nodejs.cn/download/ 通过  uname -a ...

  8. SQL Server - 使用 Merge 语句实现表数据之间的对比同步

    表数据之间的同步有很多种实现方式,比如删除然后重新 INSERT,或者写一些其它的分支条件判断再加以 INSERT 或者 UPDATE 等.包括在 SSIS Package 中也可以通过 Lookup ...

  9. iftop网络流量查看工具

    1.下载iftop源码包 mkdir /usr/local/src/iftop cd /usr/local/src/iftop wget http://www.ex-parrot.com/~pdw/i ...

  10. SQLMAP自动注入(三):参数介绍

    --delay延时扫描 --scope 从burpsuit日志中过滤日志内容,通过正则表达式筛选扫描目标,19开头,尾数为1.11.121.221的目标 --level=3 会检查user-agent ...