Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
VladK9 committed Nov 8, 2022
1 parent 6492e71 commit 227df86
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 61 deletions.
4 changes: 0 additions & 4 deletions Sources/UIFloatMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class UIFloatMenu {
return vc
}

static private var containerView = ContainerView()

static private var container_VC = UIViewController()
static private var source_VC = UIViewController()

Expand Down Expand Up @@ -335,7 +333,6 @@ class UIFloatMenu {

var newView: UIView {
if let new = container_VC.view.viewWithTag(id) {
//new.isHidden = true
return new
}
return UIView()
Expand Down Expand Up @@ -386,7 +383,6 @@ class UIFloatMenu {

animator.addMovingAnimation(from: lastView, to: previousView, sourceView: previousView, in: previousView)
animator.addCompletion({ _ in
showTo(containerView, positions: correct, animation: .fade)
lastView.removeFromSuperview()
queue.removeLast()
})
Expand Down
5 changes: 2 additions & 3 deletions Sources/UIFloatMenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ class UIFloatMenuController: UIViewController, UIGestureRecognizerDelegate {
// MARK: - detect device rotations
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)

UIView.animate(withDuration: 0.01) {
self.backgroundView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
}
Expand All @@ -205,7 +204,7 @@ class UIFloatMenuController: UIViewController, UIGestureRecognizerDelegate {
for index in 0..<UIFloatMenu.queue.count {
if let menuView = self.view.viewWithTag(UIFloatMenu.queue[index].uuid) {
if device == .pad {
let layout = Layout.determineLayout()
let layout = UIFloatMenuHelper.Layout.determineLayout()

let current_presentation = (UIFloatMenu.queue[index].config.presentation)!
let position: UIFloatMenuPresentStyle!
Expand Down Expand Up @@ -240,7 +239,7 @@ class UIFloatMenuController: UIViewController, UIGestureRecognizerDelegate {
}
menu.showTo(menuView, positions: position, iPad_window_width: 0, animation: .default(animated: false))
} else if device == .phone {
if Orientation.isLandscape {
if UIFloatMenuHelper.Orientation.isLandscape {
menuView.center = self.view.center
} else {
menu.showTo(menuView, positions: UIFloatMenuHelper.correctPosition((self.queue.last?.config.presentation)!), animation: .default(animated: false))
Expand Down
96 changes: 46 additions & 50 deletions Sources/UIFloatMenuHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,62 +124,58 @@ class UIFloatMenuHelper {
return ""
}

}

// MARK: - Layout
struct Layout {

enum LayoutStyle: String {
case iPadFullScreen = "iPad Full Screen"
case iPadHalfScreen = "iPad 1/2 Screen"
case iPadTwoThirdScreen = "iPad 2/3 Screen"
case iPadOneThirdScreen = "iPad 1/3 Screen"
case iPhoneFullScreen = "iPhone"
}

static func determineLayout() -> LayoutStyle {
if UIDevice.current.userInterfaceIdiom == .phone {
return .iPhoneFullScreen
}

let screenSize = UIScreen.main.bounds.size
let appSize = UIApplication.shared.windows[0].bounds.size
let screenWidth = screenSize.width
let appWidth = appSize.width

if screenSize == appSize {
return .iPadFullScreen
// MARK: - Layout
struct Layout {
enum LayoutStyle: String {
case iPadFullScreen = "iPad Full Screen"
case iPadHalfScreen = "iPad 1/2 Screen"
case iPadTwoThirdScreen = "iPad 2/3 Screen"
case iPadOneThirdScreen = "iPad 1/3 Screen"
case iPhoneFullScreen = "iPhone"
}

let persent = CGFloat(appWidth / screenWidth) * 100.0

if persent <= 55.0 && persent >= 45.0 {
return .iPadHalfScreen
} else if persent > 55.0 {
return .iPadTwoThirdScreen
} else {
return .iPadOneThirdScreen
static func determineLayout() -> LayoutStyle {
if UIDevice.current.userInterfaceIdiom == .phone {
return .iPhoneFullScreen
}

let screenSize = UIScreen.main.bounds.size
let appSize = UIApplication.shared.windows[0].bounds.size
let screenWidth = screenSize.width
let appWidth = appSize.width

if screenSize == appSize {
return .iPadFullScreen
}

let persent = CGFloat(appWidth / screenWidth) * 100.0

if persent <= 55.0 && persent >= 45.0 {
return .iPadHalfScreen
} else if persent > 55.0 {
return .iPadTwoThirdScreen
} else {
return .iPadOneThirdScreen
}
}
}

}

// MARK: - Orientation
struct Orientation {

static var isLandscape: Bool {
get {
return UIDevice.current.orientation.isValidInterfaceOrientation
? UIDevice.current.orientation.isLandscape
: (UIApplication.shared.windows.first?.windowScene?.interfaceOrientation.isLandscape)!
// MARK: - Orientation
struct Orientation {
static var isLandscape: Bool {
get {
return UIDevice.current.orientation.isValidInterfaceOrientation
? UIDevice.current.orientation.isLandscape
: (UIApplication.shared.windows.first?.windowScene?.interfaceOrientation.isLandscape)!
}
}
}

static var isPortrait: Bool {
get {
return UIDevice.current.orientation.isValidInterfaceOrientation
? UIDevice.current.orientation.isPortrait
: (UIApplication.shared.windows.first?.windowScene?.interfaceOrientation.isPortrait)!
static var isPortrait: Bool {
get {
return UIDevice.current.orientation.isValidInterfaceOrientation
? UIDevice.current.orientation.isPortrait
: (UIApplication.shared.windows.first?.windowScene?.interfaceOrientation.isPortrait)!
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/UIFloatMenuView/UIFloatMenuHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class UIFloatMenuHeaderView: UIView {
super.init(frame: CGRect.zero)
let appRect = UIApplication.shared.windows[0].bounds
let device = UIDevice.current.userInterfaceIdiom
let width = (device == .pad ? menuConfig.viewWidth_iPad : (Orientation.isPortrait ? appRect.width-30 : appRect.width/2.5))!
let width = (device == .pad ? menuConfig.viewWidth_iPad : (UIFloatMenuHelper.Orientation.isPortrait ? appRect.width-30 : appRect.width/2.5))!

self.headerConfig = headerConfig

Expand Down
6 changes: 3 additions & 3 deletions Sources/UIFloatMenuView/UIFloatMenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ class UIFloatMenuView: UIView, UITableViewDelegate, UITableViewDataSource, UIGes
let appRect = UIApplication.shared.windows[0].bounds
var topSpace: CGFloat {
let device = UIDevice.current.userInterfaceIdiom
return device == .pad ? 250 : (Orientation.isLandscape ? 30 : 120)
return device == .pad ? 250 : (UIFloatMenuHelper.Orientation.isLandscape ? 30 : 120)
}

let maxH = appRect.height-topPadding-bottomPadding-topSpace
Expand All @@ -402,9 +402,9 @@ class UIFloatMenuView: UIView, UITableViewDelegate, UITableViewDataSource, UIGes
if device == .pad {
return currentWidth
} else if device == .phone {
if Orientation.isLandscape {
if UIFloatMenuHelper.Orientation.isLandscape {
return appRect.height-30
} else if Orientation.isPortrait {
} else if UIFloatMenuHelper.Orientation.isPortrait {
return appRect.width-30
}
}
Expand Down

0 comments on commit 227df86

Please sign in to comment.