-
-
Notifications
You must be signed in to change notification settings - Fork 19
FullScreenable
林洵锋 edited this page Sep 25, 2022
·
10 revisions
- 若项目支持横屏(Landscape)则跳过此配置步骤
- 若项目只支持竖屏(Portrait)的话需要在
AppDelegate中实现如下方法
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return UIApplication.shared.lxf.currentVcOrientationMask
}方法与属性的调用都需要命名空间加上
lxf,如isFullScreen->lxf.isFullScreen
isFullScreen : 获取当前遵守协议者是否为全屏状态func switchFullScreen(
isEnter: Bool? = nil,
specifiedView: UIView? = nil,
superView: UIView? = nil,
config: FullScreenableConfig? = nil,
completed: ((_ isFullScreen: Bool)->Void)? = nil
)| Name | Type | Desc |
|---|---|---|
| isEnter | Bool? |
是否进入全屏 |
| specifiedView | UIView? |
指定即将全屏的视图 |
| superView | UIView? |
作为退出全屏后specifiedView的父视图 |
| config | FullScreenableConfig? |
配置 |
| completed | ((_ isFullScreen: Bool)->Void)? |
进入/退出 全屏后的回调 |
当
switchFullScreen的调用者为UIView时,如果specifiedView为nil会自动填写,superView也是如此
switchFullScreen方法不推荐直接使用,不过当遵守协议者为UIViewController时,可以通过使用默认参数来切换屏幕方向lxf.switchFullScreen()

以下分两种情况说明
func enterFullScreen(
specifiedView: UIView? = nil,
config: FullScreenableConfig? = nil,
completed: FullScreenableCompleteType? = nil
)func exitFullScreen(
superView: UIView? = nil,
config: FullScreenableConfig? = nil,
completed: FullScreenableCompleteType? = nil
)以上两个方法是对
switchFullScreen的抽离,使调用时对参数的传递更加清晰
1、遵守协议 FullScreenable
class LXFFullScreenableController: UIViewController, FullScreenable { }2、指定视图进入全屏
lxf.enterFullScreen(specifiedView: cyanView)3、指定视图退出全屏,并添加到当前控制器的view上
lxf.exitFullScreen(superView: self.view)func autoFullScreen(
specifiedView: UIView? = nil,
superView: UIView? = nil,
config: FullScreenableConfig? = nil
) - 控制器可以调用该方法来注册自动进入或退出全屏
-
view手动进入全屏会屏蔽当前控制器的自动全屏功能,退出方可恢复
注: 在当前控制器下添加了子控制器时,旋转控制权就会变得很混乱,这时候需要声明谁拥有全屏旋转控制权
步骤:
1、在当前控制器的viewWillAppear指定哪个控制器(简称: vcA)拥有控制权
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// 指定当前控制器拥有控制权
lxf.becomeFullScreenMaster()
}2、且在viewWillDisappear中注销vcA的控制权
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// 注销当前控制器的控制权
lxf.resignFullScreenMaster()
}详细用法见: LXFFullScreenableMultiVcController.swift
func enterFullScreen(
specifiedView: UIView? = nil,
config: FullScreenableConfig? = nil,
completed: FullScreenableCompleteType? = nil
)func exitFullScreen(
superView: UIView? = nil,
config: FullScreenableConfig? = nil,
completed: FullScreenableCompleteType? = nil
)以上两个方法是对
switchFullScreen的抽离,使调用时对参数的传递更加清晰
1、遵守协议 FullScreenable
class LXFFullScreenView: UIButton, FullScreenable { }let cyanView = LXFFullScreenView()2、进入全屏
cyanView.lxf.enterFullScreen()3、退出全屏
cyanView.lxf.exitFullScreen()这里是对遵守了
FullScreenable协议的视图进入全屏切换,由于代码内部已经经过自动视图填写,所以直接调用相应的方法即可,当然也可以自己指定specifiedView和superView

上述的方法都有一个
config参数,默认为nil,即为默认配置
相关属性说明
| Name | Type | Desc | Default |
|---|---|---|---|
| animateDuration | Double |
进入/退出 全屏时的旋转动画时间 | 0.25 |
| enterFullScreenOrientation | UIInterfaceOrientation |
进入全屏时的初始方向 | landscapeRight |
这里我们把动画时间设置为1s,初始方向为左后来看看效果
FullScreenableConfig(
animateDuration: 1,
enterFullScreenOrientation : .landscapeLeft
)cyanView.lxf.enterFullScreen(config: diyConfig)
cyanView.lxf.exitFullScreen(config: diyConfig)