swift 屏幕的翻转 + 状态栏(statusBar)的隐藏
1.状态栏的隐藏
这个问题是基于 UIApplication.shared.isStatusBarHidden = true; 调用居然是无效的……
现在写下自己的代码,用来备忘吧……
1.首先需要复写一个 hidden 的这个属性 ,然后调用 setNeedsStatusBarAppearanceUpdate() 方法,
这样使用又觉得麻烦,所以 又多设置了一个变量 ,让使用更简单
override var prefersStatusBarHidden: Bool {
return self.isStatusBarHidden
}
var isStatusBarHidden = false {
didSet{
self.setNeedsStatusBarAppearanceUpdate()
}
}
在使用的地方调用
self.isStatusBarHidden = true
// self.isStatusBarHidden = false;
2.屏幕的翻转:
首先写下试用与 iphone 和 ipad 的
我使用的是transfrone 旋转 视图view ,这样的前提是 这个view 是present 出来的,不能用 navigationController 了
//定义枚举
enum ScreenOrientation :Int { case portrait = ;
case landscape =
} // 定义常量
let scrw = UIScreen.main.bounds.size.width;
let scrh = UIScreen.main.bounds.size.height; //定义方法
func tranformView() -> Void { if self.orientation == .landscape {
self.orientation = .portrait
}else{
self.orientation = .landscape;
} if self.orientation == .landscape { self.isStatusBarHidden = true UIView.animate(withDuration: deviceChangeOrientationTimeIntravel, animations: { self.view.transform = CGAffineTransform.init(rotationAngle: CGFloat(Double.pi / ))
self.view.bounds = CGRect(x:,y:,width:scrh,height:scrw);
self.viewWillLayoutSubviews();
self.view.layoutIfNeeded();
}) { (isFinish) in } }else{ self.isStatusBarHidden = false; UIView.animate(withDuration: deviceChangeOrientationTimeIntravel, animations: { self.view.transform = CGAffineTransform.init(rotationAngle: CGFloat())
self.view.bounds = CGRect(x:,y:,width:scrw,height:scrh);
self.viewWillLayoutSubviews();
self.view.layoutIfNeeded(); }) { (isFinish) in }
}
}
简单易懂,应该是可以使用了……
网上也找了 这个方法,但是使用的时候,只有在iphone 上用,ipad 使用无效
/*
创建个 extension
使用这个 扩展 要在 appdelegate 文件中 添加代码:
var blockRotation: Bool = false
*/
extension AppDelegate{
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { if self.blockRotation == true{ return UIInterfaceOrientationMask.all;
}else{ return UIInterfaceOrientationMask.portrait;
}
}
}
调用的时候
let appDelegate = UIApplication.shared.delegate as! AppDelegate
//横屏
@objc func hengp()->Void{ appDelegate.blockRotation = true
let value = UIInterfaceOrientation.landscapeLeft.rawValue
UIDevice.current.setValue(value, forKey: "orientation");
}
//竖屏
@objc func shup() -> Void{
appDelegate.blockRotation = false
let value = UIInterfaceOrientation.portrait.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
} //切换横竖屏 执行的代理方法 override func willRotate(to toInterfaceOrientation: UIInterfaceOrientation, duration: TimeInterval) { print("方向即将改变 \(toInterfaceOrientation)");
} override func didRotate(from fromInterfaceOrientation: UIInterfaceOrientation) {
print("方向改变完成 ");
/* 在这里更新 约束 和 frame */ UIView.animate(withDuration: deviceChangeOrientationTimeIntravel, animations: {
self.viewWillLayoutSubviews();
self.view.layoutIfNeeded(); }) { (isFinish) in if isFinish == true{ }
}
}
swift 屏幕的翻转 + 状态栏(statusBar)的隐藏的更多相关文章
- [Swift]动态变化顶部状态栏(statusBar)的颜色
顶部状态栏(statusBar)的两种样式: (1).default 样式:黑色. (2).light 样式:白色 一.无导航栏情况 如果没有使用导航控制器 UINavigationControlle ...
- 张高兴的 UWP 开发笔记:手机状态栏 StatusBar
UWP 有关应用标题栏 TitleBar 的文章比较多,但介绍 StatusBar 的却没几篇,在这里随便写写.状态栏 StatusBar 用法比较简单,花点心思稍微设计一下,对应用会是个很好的点缀. ...
- Android动态控制状态栏显示和隐藏
记得之前有朋友在留言里让我写一篇关于沉浸式状态栏的文章,正巧我确实有这个打算,那么本篇就给大家带来一次沉浸式状态栏的微技巧讲解. 其实说到沉浸式状态栏这个名字我也是感到很无奈,真不知道这种叫法是谁先发 ...
- [置顶] IOS7状态栏StatusBar官方标准适配方法
IOS7状态栏StatusBar官方标准适配方法 hello,大家好,ios7正式版已经发布,相信大家都在以各种方式来适配ios7. 如果你已经下载了xcode5,正准备使用,你会发现各种布局的改变. ...
- Android利用反射获取状态栏(StatusBar)高度
MainActivity如下: package cc.teststatusbarheight; import java.lang.reflect.Field; import android.os.Bu ...
- 牛B的swift屏幕旋转经验终结者(OC统一思路)
牛B的swift屏幕旋转经验终结者(OC统一思路) 1.AppDelegate (1)定义变量 var blockRotation: Bool = false (2)定义方法 Swift代码 func ...
- IOS7状态栏StatusBar官方标准适配方法
IOS7状态栏StatusBar官方标准适配方法 hello,大家好,ios7正式版已经发布,相信大家都在以各种方式来适配ios7. 如果你已经下载了xcode5,正准备使用,你会发现各种布局的改变. ...
- swift 如何控制view的显示与隐藏
swift 如何控制view的显示与隐藏 UIView有一个属性 hidden let line: UILabel = UILabel() 默认是显示的 需要显示它的时候:line.hidden = ...
- iOS7隐藏状态栏 statusBar
转:http://blog.csdn.net/dqjyong/article/details/17896145 评:通过这点变化,可以看出苹果倾向于使用delegate取代全局变量. IOS7中,不仅 ...
随机推荐
- Java多线程下载初试
一.服务端/客户端代码的实现 服务端配置config @ConfigurationProperties("storage") public class StoragePropert ...
- LeetCode 317. Shortest Distance from All Buildings
原题链接在这里:https://leetcode.com/problems/shortest-distance-from-all-buildings/ 题目: You want to build a ...
- man与info
Linux系统中在线求助命令:man page 与info page 还有--help . --help没有man的详细,首先我们来看mna 命令.在linux中输入 man + 相关的文件 ,就可以 ...
- [笔记] 三元环 && 四元环计数
Thanks to i207M && iki9! 三元环计数 无向图的三元环计数 我们首先需要对无向边按一定规则定向: 设 \(in[u]\) 表示 \(u\) 的度数 若 \(in[ ...
- luogu P3709 大爷的字符串题
二次联通门 : luogu P3709 大爷的字符串题 /* luogu P3709 大爷的字符串题 莫队 看了半天题目 + 题解 才弄懂了要求什么... 维护两个数组 一个记录数字i出现了几次 一个 ...
- TensorFlow(十五):使用inception-v3实现各种图像识别
上代码: import tensorflow as tf import os import numpy as np import re from PIL import Image import mat ...
- python #!/usr/bin/python 的作用
在说之前,这里推荐写: #!/usr/bin/env python 进入正题,在 Python 里面第一行代码: #!/usr/bin/python 其他有的可能是 python2 或者 python ...
- codeforces396C
On Changing Tree CodeForces - 396C You are given a rooted tree consisting of n vertices numbered fro ...
- ftp连接
package enterprise.celerity.ac.util; import java.io.IOException;import java.io.InputStream;import ja ...
- linux下安装apache和php和mysql
我的系统环境时ubuntu 18.04.3,为了ROS: 首先:安装下面一堆软件包: sudo apt install nginx nginx-doc fcgiwrap sudo apt instal ...