Skip to content

Commit

Permalink
feat: 屏幕旋转适配
Browse files Browse the repository at this point in the history
  • Loading branch information
gu0315 committed Nov 28, 2023
1 parent 8ea07cb commit 72724fd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
Binary file not shown.
48 changes: 42 additions & 6 deletions SameLayerRendering/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import KTVHTTPCache
@main
class AppDelegate: UIResponder, UIApplicationDelegate {

open var isAllowOrientationRotation: Bool = false
open var allowOrentitaionRotation: Bool = false

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
KTVHTTPCache.logSetRecordLogEnable(false)
Expand All @@ -22,11 +22,49 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if window is ZFLandscapeWindow {
return [.landscape]
var orientationMask: ZFInterfaceOrientationMask = .portrait
if #available(iOS 16.0, *) {
orientationMask = ZFLandscapeRotationManager_iOS16.supportedInterfaceOrientations(for: window)

}else if #available(iOS 15.0, *) {
orientationMask = ZFLandscapeRotationManager_iOS15.supportedInterfaceOrientations(for: window)

}else{
orientationMask = ZFLandscapeRotationManager.supportedInterfaceOrientations(for: window)
}

if #available(iOS 16.0, *) {
if allowOrentitaionRotation {
return UIInterfaceOrientationMask.landscape
} else {
return UIInterfaceOrientationMask.portrait
}
}else {
if orientationMask != [] {
if orientationMask == .portrait {
return UIInterfaceOrientationMask.portrait
}else if orientationMask == .landscapeLeft {
return UIInterfaceOrientationMask.landscapeLeft
}else if orientationMask == .landscapeRight {
return UIInterfaceOrientationMask.landscapeRight
}else if orientationMask == .landscape {
return UIInterfaceOrientationMask.landscape
}else if orientationMask == .portraitUpsideDown {
return UIInterfaceOrientationMask.portraitUpsideDown
}else if orientationMask == .all {
return UIInterfaceOrientationMask.all
}else if orientationMask == .allButUpsideDown {
return UIInterfaceOrientationMask.allButUpsideDown
}else{
return UIInterfaceOrientationMask.all
}

}else{
return UIInterfaceOrientationMask.portrait
}
}
return .portrait
}

// MARK: UISceneSession Lifecycle

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
Expand All @@ -40,7 +78,5 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}


}

2 changes: 1 addition & 1 deletion SameLayerRendering/Component/Video/XVideoElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class XVideoElement: XSLBaseElement {
player.disableGestureTypes = .pan
player.orientationWillChange = { _, isFullScreen in
if let appdelegate = UIApplication.shared.delegate as? AppDelegate {
appdelegate.isAllowOrientationRotation = isFullScreen
appdelegate.allowOrentitaionRotation = isFullScreen
}
}
objc_setAssociatedObject(webView!, pointer, player, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
Expand Down

0 comments on commit 72724fd

Please sign in to comment.