For the practical use of protocol oriented to encapsulate functions, you can refer to my previous article [iOS protocol oriented to encapsulate blank page functions], so we will not go into the use phase. The purpose of this article is to switch a line of code to full-screen as long as the protocol is followed
If you have any questions about protocol orientation you can take a look at my previous two articles
Ios-swift Protocol Oriented Programming (I)
Ios-swift Protocol Oriented Programming (II)
Open source library
Name | Link |
---|---|
GitHub | LXFProtocolTool |
Wiki | The Wiki page |
In this paper, the Demo | LXFFullScreenable |
Install using Cocoapods
pod 'LXFProtocolTool/FullScreenable'
Copy the code
A, configuration,
Implement the following methods in an AppDelegate
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return UIApplication.shared.lxf.currentVcOrientationMask
}
Copy the code
Ii. Use cases
Method and attribute calls require a namespace plus LXF, such as isFullScreen -> lxf.isfullscreen
IsFullScreen: indicates whether the current protocol abuser is in full-screen stateCopy the code
func switchFullScreen(
isEnter: Bool? = nil,
specifiedView: UIView? = nil,
superView: UIView? = nil,
config: FullScreenableConfig? = nil,
completed: ((_ isFullScreen: Bool)->Void)? = nil
)
Copy the code
Name | Type | Desc |
---|---|---|
isEnter | Bool? |
Whether to enter full screen |
specifiedView | UIView? |
Specifies the view to be full-screen |
superView | UIView? |
As the parent view of specifiedView after exiting full screen |
config | FullScreenableConfig? |
configuration |
completed | ((_ isFullScreen: Bool)->Void)? |
Callback after entering/exiting full screen |
When the caller of switchFullScreen is UIView, it is filled in automatically if specifiedView is nil, as is the case with superView
The switchFullScreen method is not recommended directly, but when the protocol is followed by a UIViewController, you can switch the screen orientation by using the default parameter lxf.switchFullScreen().
The following two cases are described
UIViewController
func enterFullScreen(
specifiedView: UIView,
config: FullScreenableConfig? = nil,
completed: FullScreenableCompleteType? = nil
)
Copy the code
func exitFullScreen(
superView: UIView,
config: FullScreenableConfig? = nil,
completed: FullScreenableCompleteType? = nil
)
Copy the code
The above two methods are the extraction of switchFullScreen to make the passing of parameters clearer when calling
1. Comply with the protocol FullScreenable
class LXFFullScreenableController: UIViewController.FullScreenable {}Copy the code
2. Enter the full screen view
lxf.enterFullScreen(specifiedView: cyanView)
Copy the code
3. Exit the full screen view and add it to the view of the current controller
lxf.exitFullScreen(superView: self.view)
Copy the code
🔥 automatically entered into | out of full screen
func autoFullScreen(
specifiedView: UIView,
superView: UIView,
config: FullScreenableConfig? = nil
)
Copy the code
- Controllers can call this method to register to enter or exit the full screen automatically without affecting each other.
view
If you enter the full screen mode manually, the automatic full screen function of the current controller is disabled
UIView
func enterFullScreen(
specifiedView: UIView? = nil,
config: FullScreenableConfig? = nil,
completed: FullScreenableCompleteType? = nil
)
Copy the code
func exitFullScreen(
superView: UIView? = nil,
config: FullScreenableConfig? = nil,
completed: FullScreenableCompleteType? = nil
)
Copy the code
The above two methods are the extraction of switchFullScreen to make the passing of parameters clearer when calling
1. Comply with the protocol FullScreenable
class LXFFullScreenView: UIButton.FullScreenable {}Copy the code
let cyanView = LXFFullScreenView(a)Copy the code
2. Enter the full screen
cyanView.lxf.enterFullScreen()
Copy the code
3. Exit the full screen
cyanView.lxf.exitFullScreen()
Copy the code
Here is a full screen switch for the view that complies with the FullScreenable protocol. Since the code has been filled in by automatic view, you can directly call the corresponding method, of course, you can also specify specifiedView and superView by yourself
FullScreenableConfig
All of the above methods take a config argument that defaults to nil, which is the default configuration
Related Attributes
Name | Type | Desc | Default |
---|---|---|---|
animateDuration | Double |
Rotation animation time when entering/exiting full screen | 0.25 |
enterFullScreenOrientation | UIInterfaceOrientation |
Initial orientation when entering full screen | landscapeRight |
So here we’re going to set the animation time to 1s, and we’re going to start to the left and we’re going to see what happens
FullScreenableConfig(
animateDuration: 1,
enterFullScreenOrientation : .landscapeLeft
)
Copy the code
cyanView.lxf.enterFullScreen(config: diyConfig)
cyanView.lxf.exitFullScreen(config: diyConfig)
Copy the code
conclusion
The relevant instructions have been listed here, what is not clear can download the Demo to have a look, or leave a comment below the article to ask questions
LXFProtocolTool is a quick and convenient protocol encapsulation tool. In addition to the full-screen rotation function mentioned in this article, you can find the LXFProtocolTool on the Wiki homepage. If you have what want to achieve the function can also put forward, like to give a Star to encourage me 🚀 🚀 🚀, thank you for your support!