iOS - iphoneX系列 - 全局配置的基本信息
/// 获得当前窗口
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系列 - 全局配置的基本信息的更多相关文章
- Apache系列:Apache的全局配置
配置文件组成: 整个配置文件由3段组成: (1)全局配置:对主服务器或虚拟机都有效,且有些功能是服务器自身工作属性: (2)主服务器:主站属性: (3)虚拟主机:虚拟主机及属性定义 注:第二段和第三段 ...
- iOS iPhoneX/iPhoneXS/iPhoneXR/iPhoneXS Max系列适配
以前异性屏只有一款iPhoneX,所以在适配的时候直接判断高度是否等于812即可判断是否是iPhoneX #define IS_IPHONE_X (IS_IPHONE && SCREE ...
- iOS开发系列--通知与消息机制
概述 在多数移动应用中任何时候都只能有一个应用程序处于活跃状态,如果其他应用此刻发生了一些用户感兴趣的那么通过通知机制就可以告诉用户此时发生的事情.iOS中通知机制又叫消息机制,其包括两类:一类是本地 ...
- iOS开发系列--数据存取
概览 在iOS开发中数据存储的方式可以归纳为两类:一类是存储为文件,另一类是存储到数据库.例如前面IOS开发系列-Objective-C之Foundation框架的文章中提到归档.plist文件存储, ...
- iOS开发系列--网络开发
概览 大部分应用程序都或多或少会牵扯到网络开发,例如说新浪微博.微信等,这些应用本身可能采用iOS开发,但是所有的数据支撑都是基于后台网络服务器的.如今,网络编程越来越普遍,孤立的应用通常是没有生命力 ...
- 【转】iOS开发系列--数据存取
原文: http://www.cnblogs.com/kenshincui/p/4077833.html#SQLite 概览 在iOS开发中数据存储的方式可以归纳为两类:一类是存储为文件,另一类是存储 ...
- iOS开发系列--通知与消息机制--转
来自:http://www.cocoachina.com/ios/20150318/11364.html 概述 在多数移动应用中任何时候都只能有一个应用程序处于活跃状态,如果其他应用此刻发生了一些用户 ...
- iOS开发系列--Swift语言
概述 Swift是苹果2014年推出的全新的编程语言,它继承了C语言.ObjC的特性,且克服了C语言的兼容性问题.Swift发展过程中不仅保留了ObjC很多语法特性,它也借鉴了多种现代化语言的特点,在 ...
- iOS开发系列--App扩展开发
概述 从iOS 8 开始Apple引入了扩展(Extension)用于增强系统应用服务和应用之间的交互.它的出现让自定义键盘.系统分享集成等这些依靠系统服务的开发变成了可能.WWDC 2016上众多更 ...
随机推荐
- html表单中get与post之间的区别
当用户在 HTML 表单 (HTML Form) 中输入信息并提交之后,有两种方法将信息从浏览器传送到 Web 服务器 (Web Server). 一种方法是通过 URL,另外一种是在 HTTP Re ...
- LeetCode 题解 Permutation Sequence 需要优化!
题目大意:给出n和k,找到1..n这些数组成的有序全排列中的第k个. 首先,n的全排列可以分成n组,每一组由n-1个数组成. 例如 3的全排列,分成三组: 1 2 3 和 1 3 2 2 1 3 ...
- iOS 视图间的几种通信方式
注:此处视图为广义上的视图,不限于View,ViewController之类的都算. 大致分为三种,Notification, delegate, block 例: 假设要在A视图中调起B视图,B视图 ...
- Linux下Mongodb安装和启动配置 原
1.安装 略 2.配置 01.mkdir /usr/local/mongodb/data 0.touch /usr/local/mongodb/logs 03.cd /usr/local/mongod ...
- 为什么MySQL不推荐使用子查询和join
前言: 1.对于mysql,不推荐使用子查询和join是因为本身join的效率就是硬伤,一旦数据量很大效率就很难保证,强烈推荐分别根据索引单表取数据,然后在程序里面做join,merge数据. 2.子 ...
- 4.Python文件操作
文件内需要写入的内容 Seems the love I’ve ever known 看来,过去我所知道的爱情 Has always been the most destructive kind 似乎总 ...
- mycat 多个逻辑库加读写分离
上3篇笔记主要记录了,读写分离,单库分表,分库分表 这次改动了下,实现了分库分表以及读写分离,基于多个逻辑库,先看配置文件 server.xml <user name="root&qu ...
- [Redis]Redis的快速配置使用(图)
--------------------------------------------------------------------------------------------------- ...
- js数组对象--数据格式的转换(字符串,对象的取值与赋值)
材料:提供一份数据:arr=[ {value:335, name:'直接访问'}, {value:310, name:'邮件营销'}, {value:234, name:'联盟广告'}, {value ...
- idea2017授权
http://blog.csdn.net/qq_27686779/article/details/78870816 文章中注册码: BIG3CLIK6F-eyJsaWNlbnNlSWQiOiJCSUc ...