/// 获得当前窗口
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. C#中关于@的用法

    1. 加在字符串前面,字符串中的 \ 失去转义符的作用,直接写字符串而不需要考虑转义字符 string path = @"C:\Windows\"; // 如果不加 @,编译会提示 ...

  2. 2018SDIBT_国庆个人第三场

    A - A CodeForces - 1042A There are nn benches in the Berland Central park. It is known that aiai peo ...

  3. 2018.3,GC可控了

    如题,不再像以前那样由系统决定什么时候进行GC,现在可以通过设置,决定自己手动回收还是使用传统的系统决定方式. 传统方式不可控,就算是手动调用了GC.COLLECT,系统也不一定会立即执行.

  4. UGUI 判断元素进入舞台

    void LateUpdate () { if(!_isLoaded){ RectTransform rectt=this.GetComponent<RectTransform>(); f ...

  5. ASP.NET 工作流:支持长时间运行操作的 Web 应用程序

    ASP.NET 工作流 支持长时间运行操作的 Web 应用程序 Michael Kennedy   代码下载位置:MSDN 代码库 在线浏览代码 本文将介绍以下内容: 独立于进程的工作流 同步和异步活 ...

  6. Hibernate 再接触 多对多单向双向关联

    情景:一个老师可能有多个学生,一个学生也可能有多个老师 多对一单向: 例如老师知道自己教哪些学生,学生却不知道自己被哪些老师教 方法:使用第三张表 分别存两张表的id annotation Stude ...

  7. Working with the Dynamic Type in C#

    Working with the Dynamic Type in C# https://www.red-gate.com/simple-talk/dotnet/c-programming/workin ...

  8. 吴裕雄 python神经网络 水果图片识别(4)

    # coding: utf-8 # In[1]:import osimport numpy as npfrom skimage import color, data, transform, io # ...

  9. 使用Python抓取猫眼近10万条评论并分析

    <一出好戏>讲述人性,使用Python抓取猫眼近10万条评论并分析,一起揭秘“这出好戏”到底如何? 黄渤首次导演的电影<一出好戏>自8月10日在全国上映,至今已有10天,其主演 ...

  10. 项目IDEA启动配置

    在所有java启动项中加入 -Djute.maxbuffer=2048000 tomcat 在catalina.bat 中第一行加入 set JAVA_OPTS=-Djute.maxbuffer=20 ...