Skip to content

Commit 7373eca

Browse files
committed
feat: FullScreenable - 新增可指定退出全屏时的动画目标位置
1 parent a4293cc commit 7373eca

File tree

1 file changed

+49
-11
lines changed

1 file changed

+49
-11
lines changed

LXFProtocolTool/Classes/FullScreenable/FullScreenable.swift

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ extension FullScreenable {
6161
isEnter: Bool? = nil,
6262
specifiedView: UIView?,
6363
superView: UIView?,
64+
exitFullScreenToFrame : CGRect?,
6465
config: FullScreenableConfig? = nil,
6566
isAutoTrigger: Bool = false,
6667
completed: FullScreenableCompleteType?
@@ -98,12 +99,16 @@ extension FullScreenable {
9899
if _isEnter { // 进入全屏
99100
if self.isFullScreen { return }
100101
self.lxf_specifiedView = specifiedView
101-
self.lxf_superView = superView
102+
self.lxf_superView = superView ?? specifiedView?.superview
102103
self.lxf_selfFrame = specifiedView?.frame
103104

104105
specifiedView?.removeFromSuperview()
105-
if specifiedView != nil {
106-
UIApplication.shared.keyWindow?.addSubview(specifiedView!)
106+
if let _specifiedView = self.lxf_specifiedView,
107+
let _superView = self.lxf_superView,
108+
let keyWindow = UIApplication.shared.keyWindow {
109+
keyWindow.addSubview(_specifiedView)
110+
// 先将 specifiedView 调整为 keyWindow 下的 frame
111+
_specifiedView.frame = _superView.convert(_specifiedView.frame, to: keyWindow)
107112
}
108113
UIView.animate(withDuration: _config.animateDuration, animations: {
109114
specifiedView?.frame = UIScreen.main.bounds
@@ -115,12 +120,13 @@ extension FullScreenable {
115120
if !self.isFullScreen { return }
116121
let specifiedView = self.lxf_specifiedView
117122
UIView.animate(withDuration: _config.animateDuration, animations: {
118-
specifiedView?.frame = self.lxf_selfFrame ?? CGRect.zero
123+
specifiedView?.frame = exitFullScreenToFrame ?? self.lxf_selfFrame ?? .zero
119124
}, completion: { _ in
120125
specifiedView?.removeFromSuperview()
121126
let superView = superView == nil ? self.lxf_superView : superView
122127
if specifiedView != nil {
123128
superView?.addSubview(specifiedView!)
129+
specifiedView?.frame = self.lxf_selfFrame ?? .zero
124130
}
125131
guard let completed = completed else{ return }
126132
completed(isEnter)
@@ -132,7 +138,14 @@ extension FullScreenable {
132138
}
133139
public extension LXFNameSpace where Base: FullScreenable {
134140

135-
func switchFullScreen(isEnter: Bool? = nil, specifiedView: UIView? = nil, superView: UIView? = nil, config: FullScreenableConfig? = nil, completed: FullScreenableCompleteType? = nil) {
141+
func switchFullScreen(
142+
isEnter: Bool? = nil,
143+
specifiedView: UIView? = nil,
144+
superView: UIView? = nil,
145+
exitFullScreenToFrame: CGRect? = nil,
146+
config: FullScreenableConfig? = nil,
147+
completed: FullScreenableCompleteType? = nil
148+
) {
136149
var specifiedView = specifiedView
137150
var superView = superView
138151

@@ -147,6 +160,7 @@ public extension LXFNameSpace where Base: FullScreenable {
147160
isEnter: isEnter,
148161
specifiedView: specifiedView,
149162
superView: superView,
163+
exitFullScreenToFrame: exitFullScreenToFrame,
150164
config: config,
151165
completed: completed
152166
)
@@ -214,7 +228,7 @@ extension UIViewController: AssociatedObjectStore {
214228
self.lxf_viewWillDisappear(animated)
215229
}
216230

217-
@objc func lxf_orientationChangeNotification(){
231+
@objc func lxf_orientationChangeNotification() {
218232
if !LXFCanControlFullScreen(self) { return }
219233

220234
if lxf_disableAutoFullScreen { return }
@@ -259,7 +273,11 @@ public extension LXFNameSpace where Base : UIViewController, Base: FullScreenabl
259273
UIApplication.shared.lxf.currentFullScreenMaster = nil
260274
}
261275

262-
func enterFullScreen(specifiedView: UIView, config: FullScreenableConfig? = nil, completed: FullScreenableCompleteType? = nil) {
276+
func enterFullScreen(
277+
specifiedView: UIView,
278+
config: FullScreenableConfig? = nil,
279+
completed: FullScreenableCompleteType? = nil
280+
) {
263281
if !LXFCanControlFullScreen(self.base) { return }
264282

265283
UIApplication.shared.lxf.currentFullScreenConfig.supportInterfaceOrientation = .landscape
@@ -273,7 +291,11 @@ public extension LXFNameSpace where Base : UIViewController, Base: FullScreenabl
273291
)
274292
}
275293

276-
func exitFullScreen(superView: UIView, config: FullScreenableConfig? = nil, completed: FullScreenableCompleteType? = nil) {
294+
func exitFullScreen(
295+
superView: UIView,
296+
config: FullScreenableConfig? = nil,
297+
completed: FullScreenableCompleteType? = nil
298+
) {
277299
if !LXFCanControlFullScreen(self.base) { return }
278300

279301
if self.base.lxf_isRegisteAutoFullScreen {
@@ -291,7 +313,12 @@ public extension LXFNameSpace where Base : UIViewController, Base: FullScreenabl
291313
self.base.lxf_disableAutoFullScreen = false
292314
}
293315

294-
func autoFullScreen(specifiedView: UIView, superView: UIView, config: FullScreenableConfig? = nil) {
316+
func autoFullScreen(
317+
specifiedView: UIView,
318+
superView: UIView,
319+
exitFullScreenToFrame: CGRect? = nil,
320+
config: FullScreenableConfig? = nil
321+
) {
295322
if !LXFCanControlFullScreen(self.base) { return }
296323

297324
self.base.initAutoFullScreen()
@@ -312,6 +339,7 @@ public extension LXFNameSpace where Base : UIViewController, Base: FullScreenabl
312339
isEnter: false,
313340
specifiedView: specifiedView,
314341
superView: superView,
342+
exitFullScreenToFrame: exitFullScreenToFrame,
315343
config: _config,
316344
isAutoTrigger: true,
317345
completed: nil)
@@ -323,6 +351,7 @@ public extension LXFNameSpace where Base : UIViewController, Base: FullScreenabl
323351
isEnter: true,
324352
specifiedView: specifiedView,
325353
superView: superView,
354+
exitFullScreenToFrame: exitFullScreenToFrame,
326355
config: _config,
327356
isAutoTrigger: true,
328357
completed: nil)
@@ -334,6 +363,7 @@ public extension LXFNameSpace where Base : UIViewController, Base: FullScreenabl
334363
isEnter: true,
335364
specifiedView: specifiedView,
336365
superView: superView,
366+
exitFullScreenToFrame: exitFullScreenToFrame,
337367
config: _config,
338368
isAutoTrigger: true,
339369
completed: nil)
@@ -346,7 +376,11 @@ public extension LXFNameSpace where Base : UIViewController, Base: FullScreenabl
346376
}
347377

348378
public extension LXFNameSpace where Base : UIView, Base : FullScreenable {
349-
func enterFullScreen(specifiedView: UIView? = nil, config: FullScreenableConfig? = nil, completed: FullScreenableCompleteType? = nil) {
379+
func enterFullScreen(
380+
specifiedView: UIView? = nil,
381+
config: FullScreenableConfig? = nil,
382+
completed: FullScreenableCompleteType? = nil
383+
) {
350384
let curVc = base.viewController()
351385
if !LXFCanControlFullScreen(curVc) { return }
352386

@@ -361,7 +395,11 @@ public extension LXFNameSpace where Base : UIView, Base : FullScreenable {
361395
)
362396
}
363397

364-
func exitFullScreen(superView: UIView? = nil, config: FullScreenableConfig? = nil, completed: FullScreenableCompleteType? = nil) {
398+
func exitFullScreen(
399+
superView: UIView? = nil,
400+
config: FullScreenableConfig? = nil,
401+
completed: FullScreenableCompleteType? = nil
402+
) {
365403
let curVc = base.lxf_superView?.viewController()
366404
if !LXFCanControlFullScreen(curVc) { return }
367405

0 commit comments

Comments
 (0)