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中,不仅 ...
随机推荐
- Spring MVC的方法返回值和参数传递
1. SpringMVC方法的返回值类型 3.1String类作为返回值 3.1.1Controller层 /** * 返回值类型为String时,一般用于返回视图名称 * 1.当方法返回值为null ...
- docker学习(四)
一.Docker数据管理 在容器中管理数据主要有两种方式:1.数据卷(Data volumes)2.数据卷容器(Data volume containers) 1.数据卷数据卷是一个可供一个或多个容器 ...
- Linux命令的详解
cat /etc/passwd文件中的每个用户都有一个对应的记录行,记录着这个用户的一下基本属性.该文件对所有用户可读. /etc/shadow 文件正如他 ...
- PHP基础语法之 位运算
写了几年PHP的人都好奇说,没有用过位运算符.所以,此处你看二进制看的头晕,就去T¥M¥D吧. 位运算符基本不用,我们也将这个知识设置为了解级别.位运算符的知识点,你不想学习也可以.等以后用到位运算的 ...
- C#第三章
一.ImageList:存储图像集合 Images 存储的所有图像 ImageSize 图像的大小 ColorDepth 颜色数 TransparentColor 被视为透明的颜色 先设置ColorD ...
- DOM Composition 事件
做实时的表单表单校验时,如果输入的是非拉丁语言,那你可能会遇到下面的问题: 如上图所示,文本框不允许输入 ' 之类的特殊字符,当用户在敲击拼音.还未最终输入时就已经触发了校验,提示输入不合法,有点尴尬 ...
- LibreOJ #6220. sum
二次联通门 : LibreOJ #6220. sum /* LibreOJ #6220. sum 对所有数做一个前缀和 如果某一位模N等于另一位 则他们中间的一段的和一定为N的倍数 自己感悟一下 (M ...
- a=”hello”和b=”世界”编码成bytes类型
a="hello" c=a.encode(encoding='utf-8') a = b'hello' b="世界" b = b.encode(encoding ...
- Semaphore信号量原理
package com.maven.info.semaphore; import java.util.ArrayList; import java.util.List; import java.uti ...
- 【转】gcc的__builtin_函数介绍
转自:http://blog.csdn.net/jasonchen_gbd/article/details/44948523 GCC提供了一系列的builtin函数,可以实现一些简单快捷的功能来方便程 ...