mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 12:14:08 +00:00
Add iOS option to lock portrait mode in browsing
This commit is contained in:
17
iOS/AppDelegate.swift
Normal file
17
iOS/AppDelegate.swift
Normal file
@@ -0,0 +1,17 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
final class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
var orientationLock = UIInterfaceOrientationMask.all
|
||||
|
||||
private(set) static var instance: AppDelegate!
|
||||
|
||||
func application(_: UIApplication, supportedInterfaceOrientationsFor _: UIWindow?) -> UIInterfaceOrientationMask {
|
||||
orientationLock
|
||||
}
|
||||
|
||||
func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { // swiftlint:disable:this discouraged_optional_collection
|
||||
AppDelegate.instance = self
|
||||
return true
|
||||
}
|
||||
}
|
31
iOS/Orientation.swift
Normal file
31
iOS/Orientation.swift
Normal file
@@ -0,0 +1,31 @@
|
||||
import CoreMotion
|
||||
import Defaults
|
||||
import Logging
|
||||
import UIKit
|
||||
|
||||
struct Orientation {
|
||||
static var logger = Logger(label: "stream.yattee.orientation")
|
||||
|
||||
static func lockOrientation(_ orientation: UIInterfaceOrientationMask) {
|
||||
if let delegate = AppDelegate.instance {
|
||||
delegate.orientationLock = orientation
|
||||
|
||||
let orientationString = orientation == .portrait ? "portrait" : orientation == .landscapeLeft ? "landscapeLeft" :
|
||||
orientation == .landscapeRight ? "landscapeRight" : orientation == .portraitUpsideDown ? "portraitUpsideDown" :
|
||||
orientation == .landscape ? "landscape" : orientation == .all ? "all" : "allButUpsideDown"
|
||||
|
||||
logger.info("locking \(orientationString)")
|
||||
}
|
||||
}
|
||||
|
||||
static func lockOrientation(_ orientation: UIInterfaceOrientationMask, andRotateTo rotateOrientation: UIInterfaceOrientation? = nil) {
|
||||
lockOrientation(orientation)
|
||||
|
||||
guard !rotateOrientation.isNil else {
|
||||
return
|
||||
}
|
||||
|
||||
UIDevice.current.setValue(rotateOrientation!.rawValue, forKey: "orientation")
|
||||
UINavigationController.attemptRotationToDeviceOrientation()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user