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

横屏切换

parent 16592938
......@@ -21,6 +21,19 @@ import HyphenateChat
@main
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?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
......@@ -140,6 +153,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, WXApiDelegate {
return true
}
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return .all
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if let host = url.host, host.contains("platformId=wechat") {
......
......@@ -21,12 +21,18 @@ class YHOrderDetailViewController: YHBaseViewController {
view.backgroundColor = .clear
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
setView()
getWhiteList()
getData()
// 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() {
......
......@@ -36,7 +36,10 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
private var isMessageListHidden = false //默认展示
// MARK: - UI Components
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .all // 返回支持的方向
}
private lazy var bottomInputBar: YHInputBottomBar = {
let view = YHInputBottomBar()
view.textViewTappedEvent = { [weak self] in
......@@ -116,6 +119,12 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
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
init(id: Int, url: String? = nil, title: String? = nil, roomId: String? = nil) {
......@@ -189,6 +198,7 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
containerView.addSubview(messageListView)
containerView.addSubview(messageListStateButton)
containerView.addSubview(closeButton)
containerView.addSubview(playButton)
bottomImageView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
......@@ -215,7 +225,13 @@ class YHLivePlayerViewController: YHBasePlayerViewController {
make.right.equalToSuperview().offset(-12)
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
self?.closeLive()
}
......@@ -905,6 +921,43 @@ extension YHLivePlayerViewController {
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) {
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 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<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>
<false/>
<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