iOS(Swift)—仿支付宝我的二维码页面系统亮度调整
来源:互联网 发布:微信秒红包软件 编辑:程序博客网 时间:2024/05/17 22:18
之前已经把OC的实现方案完成,现在我就不介绍逻辑了,想必懂swift的朋友一定懂得OC吧
这里只把资源的链接附上
OC_Demo下载地址
Swift_Demo下载地址
还是把主要的代码贴一下
1. AppDelegate.swift中代码:
// 程序启动完成 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. self.window = UIWindow (frame: UIScreen.main.bounds) self.window?.rootViewController = UINavigationController (rootViewController: ViewController()) self.window?.makeKeyAndVisible() USER_DEFAULTS .set(false, forKey: ISQRCONTROLLER) return true }// 正在使用应用的时候按“home”键,恢复系统的亮度 func applicationWillResignActive(_ application: UIApplication) { let brights:float_t = USER_DEFAULTS .value(forKey: SCREEN_BRIGHT) as! Float print("当前亮度00: \(brights)") UIScreen.main.brightness = CGFloat(brights) }// 应用成前台运行的时候,(即上次再使用APP的时候,突然按“home”键后,过一定时间又想用APP,如果是从二维码页面退出到后台,需要使二维码页面变亮(这时二维码的控制器中的几个方法不起作用,就靠这里了)) func applicationDidBecomeActive(_ application: UIApplication) { let isQR = Bool(USER_DEFAULTS .value(forKey: ISQRCONTROLLER) as! Bool) if isQR { UIScreen.main.brightness = 0.6 }else{ USER_DEFAULTS .set(UIScreen.main.brightness, forKey: SCREEN_BRIGHT) } }
2. ViewController.swift就是一个过渡页面,里面一个按钮,点击该按钮跳转到二维码二面:
// ViewController.swiftimport UIKitclass ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor .white let qRBtn:UIButton = UIButton (frame: CGRect(x: 60, y:100, width: 90, height: 30)) qRBtn.layer.borderColor = UIColor .blue.cgColor qRBtn.layer.borderWidth = 1.0 qRBtn.layer.cornerRadius = 5.0 qRBtn.layer.masksToBounds = true qRBtn .setTitle("我的二维码", for: UIControlState.normal) qRBtn.titleLabel?.font = UIFont .systemFont(ofSize: 14) qRBtn .setTitleColor(UIColor.blue, for: UIControlState.normal) qRBtn .addTarget(self, action: #selector(ViewController.btnClick), for: UIControlEvents.touchUpInside) self.view .addSubview(qRBtn) } @objc func btnClick() -> Void { self.navigationController?.pushViewController(QRCodeController(), animated: true) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. }}
3. QRCodeController.swift中代码:
// Created by Lijinkui on 2017/10/25.// Copyright © 2017 year Lijinkui. All rights reserved.//import UIKitpublic let ScreenW = UIScreen.main.bounds.widthpublic let ScreenH = UIScreen.main.bounds.heightpublic let USER_DEFAULTS = UserDefaults.standardpublic let SCREEN_BRIGHT = "screenBrights"public let ISQRCONTROLLER = "isQRController"var currentLight: CGFloat = 0;class QRCodeController: UIViewController { override func viewDidLoad() { super.viewDidLoad() self .title = "我的二维码" self.view?.backgroundColor = UIColor .white let qrImg: UIImageView = UIImageView (frame: CGRect(x: ScreenW * 0.1, y: ScreenH/2 - (ScreenW*0.4), width: ScreenW * 0.8, height: ScreenW * 0.8)) qrImg.image = UIImage (named: "CodeImg") self.view?.addSubview(qrImg) } // 把将要进入二维码页面时的系统亮度保存 override func viewWillAppear(_ animated: Bool) { currentLight = CGFloat(USER_DEFAULTS .value(forKey: SCREEN_BRIGHT) as! Float) USER_DEFAULTS .set(true, forKey: ISQRCONTROLLER) } // 进入控制器完成后,让控制器高亮 override func viewDidAppear(_ animated: Bool) { UIScreen.main .brightness = 0.6 } // 退出控制器时恢复之前的亮度 override func viewWillDisappear(_ animated: Bool) { UIScreen.main.brightness = currentLight USER_DEFAULTS .set(false, forKey: ISQRCONTROLLER) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. }}
阅读全文
1 0
- iOS(Swift)—仿支付宝我的二维码页面系统亮度调整
- iOS(OC)—仿支付宝我的二维码页面系统亮度调整
- iOS调整系统屏幕亮度
- iOS调整系统屏幕亮度和音量
- iOS调整系统屏幕亮度和音量
- iOS调整系统屏幕亮度和音量
- iOS获取屏幕亮度和调整屏幕亮度的方法
- Swift3.0二维码扫描实现(写一个仿支付宝二维码扫描的效果)
- 仿支付宝登录页面
- iOS集成支付宝支付--Swift
- 仿写的类似支付宝二维码扫描的简单例子
- 仿支付宝注册页面效果
- swift系统自带二维码的生成
- iOS仿支付宝账单饼状图
- iOS 修改系统亮度
- 仿支付宝首页体验效果(Swift版本)
- iOS系统的二维码扫描
- [ios仿系列]仿支付宝手势解码
- JAVA代码实现多级树结构封装对象
- three.js 01-03 之添加光源
- Centos 7 离线安装Cloudera Manager5 和CDH5.13.0
- 详解U-Boot中printf函数的实现
- wpa_supplicant-2.6源码交叉编译
- iOS(Swift)—仿支付宝我的二维码页面系统亮度调整
- android面试-死锁条件
- 简单的okhttp封装
- 研发技能表
- session超时时间的设置
- 3_eclipse创建第一个maven项目
- EPG开发经验17.10.25
- WPF常用控件样式
- 五分钟学GIS | SuperMap iObjects .NET批量更新