Commit 15157699 authored by pete谢兆麟's avatar pete谢兆麟

横屏切换

parent 16592938
...@@ -21,6 +21,19 @@ import HyphenateChat ...@@ -21,6 +21,19 @@ import HyphenateChat
@main @main
class AppDelegate: UIResponder, UIApplicationDelegate, WXApiDelegate { class AppDelegate: UIResponder, UIApplicationDelegate, WXApiDelegate {
var blockRotation: UIInterfaceOrientationMask = .portrait{
didSet{
if blockRotation.contains(.portrait){
//强制设置成竖屏
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
} else {
//强制设置成横屏
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
}
}
}
var window: UIWindow? var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...@@ -140,6 +153,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, WXApiDelegate { ...@@ -140,6 +153,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, WXApiDelegate {
return true return true
} }
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return .all
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if let host = url.host, host.contains("platformId=wechat") { if let host = url.host, host.contains("platformId=wechat") {
......
...@@ -21,12 +21,18 @@ class YHOrderDetailViewController: YHBaseViewController { ...@@ -21,12 +21,18 @@ class YHOrderDetailViewController: YHBaseViewController {
view.backgroundColor = .clear view.backgroundColor = .clear
return view return view
}() }()
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
setView() setView()
getWhiteList() getWhiteList()
getData() getData()
// Do any additional setup after loading the view. // Do any additional setup after loading the view.
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController?.setNeedsStatusBarAppearanceUpdate()
let orientation = UIInterfaceOrientation.landscapeLeft
UIDevice.current.setValue(orientation.rawValue, forKey: "orientation")
} }
func getData() { func getData() {
......
...@@ -36,6 +36,9 @@ class YHLivePlayerViewController: YHBasePlayerViewController { ...@@ -36,6 +36,9 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
private var isMessageListHidden = false //默认展示 private var isMessageListHidden = false //默认展示
// MARK: - UI Components // MARK: - UI Components
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .all // 返回支持的方向
}
private lazy var bottomInputBar: YHInputBottomBar = { private lazy var bottomInputBar: YHInputBottomBar = {
let view = YHInputBottomBar() let view = YHInputBottomBar()
...@@ -116,6 +119,12 @@ class YHLivePlayerViewController: YHBasePlayerViewController { ...@@ -116,6 +119,12 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
return button return button
}() }()
private lazy var playButton: UIButton = {
let button = UIButton(type: .custom)
button.setImage(UIImage(named: "live_play_interface_orientatio"), for: .normal)
button.addTarget(self, action: #selector(playeButtonClicked), for: .touchUpInside)
return button
}()
// MARK: - Initialization // MARK: - Initialization
init(id: Int, url: String? = nil, title: String? = nil, roomId: String? = nil) { init(id: Int, url: String? = nil, title: String? = nil, roomId: String? = nil) {
...@@ -189,6 +198,7 @@ class YHLivePlayerViewController: YHBasePlayerViewController { ...@@ -189,6 +198,7 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
containerView.addSubview(messageListView) containerView.addSubview(messageListView)
containerView.addSubview(messageListStateButton) containerView.addSubview(messageListStateButton)
containerView.addSubview(closeButton) containerView.addSubview(closeButton)
containerView.addSubview(playButton)
bottomImageView.snp.makeConstraints { make in bottomImageView.snp.makeConstraints { make in
make.edges.equalToSuperview() make.edges.equalToSuperview()
} }
...@@ -216,6 +226,12 @@ class YHLivePlayerViewController: YHBasePlayerViewController { ...@@ -216,6 +226,12 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
make.width.height.equalTo(32) make.width.height.equalTo(32)
} }
playButton.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.right.equalToSuperview().offset(-16)
make.width.height.equalTo(44)
}
topBarView.closeButtonClickEvent = { [weak self] in topBarView.closeButtonClickEvent = { [weak self] in
self?.closeLive() self?.closeLive()
} }
...@@ -905,6 +921,43 @@ extension YHLivePlayerViewController { ...@@ -905,6 +921,43 @@ extension YHLivePlayerViewController {
closeLive() closeLive()
} }
//切换横屏
@objc private func playeButtonClicked() {
guard let windowScene = view.window?.windowScene else { return }
// 判断当前方向并确定新的方向
let newOrientation: UIInterfaceOrientation
if windowScene.interfaceOrientation.isLandscape {
newOrientation = .portrait
} else {
newOrientation = .landscapeRight
}
// 请求几何更新
let orientationMask: UIInterfaceOrientationMask = newOrientation == .portrait ? .portrait : .landscape
if newOrientation == .portrait {
bottomInputBar.isHidden = false
messageListView.isHidden = false
messageListStateButton.isHidden = false
closeButton.isHidden = false
topBarView.isHidden = false
} else {
bottomInputBar.isHidden = true
messageListView.isHidden = true
messageListStateButton.isHidden = true
closeButton.isHidden = true
topBarView.isHidden = true
}
if #available(iOS 16.0, *) {
windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: orientationMask))
} else {
}
}
@objc private func handlePanGesture(_ gesture: UIPanGestureRecognizer) { @objc private func handlePanGesture(_ gesture: UIPanGestureRecognizer) {
let translation = gesture.translation(in: view) let translation = gesture.translation(in: view)
......
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "live_play_interface_orientatio@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "live_play_interface_orientatio@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
...@@ -2,6 +2,14 @@ ...@@ -2,6 +2,14 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>agc_applinking_not_read_pasteboard</key> <key>agc_applinking_not_read_pasteboard</key>
<false/> <false/>
<key>CFBundleDocumentTypes</key> <key>CFBundleDocumentTypes</key>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment