diff --git a/Sources/ContainerController/ContainerController.swift b/Sources/ContainerController/ContainerController.swift index c857554..fa93e4d 100644 --- a/Sources/ContainerController/ContainerController.swift +++ b/Sources/ContainerController/ContainerController.swift @@ -108,7 +108,7 @@ open class ContainerController: NSObject { // MARK: - Positions Move - private var positionTop: CGFloat { + public var positionTop: CGFloat { var top = layout.positions.top if !isPortrait { if let landscape = layout.landscapePositions { @@ -127,8 +127,18 @@ open class ContainerController: NSObject { } return deviceHeight - middle } + + public var positionCustom: CGFloat { + var custom = layout.positions.custom ?? layout.positions.bottom + if !isPortrait { + if let landscape = layout.landscapePositions { + custom = landscape.custom ?? 0.0 + } + } + return deviceHeight - custom + } - private var positionBottom: CGFloat { + public var positionBottom: CGFloat { var bottom = layout.positions.bottom if !isPortrait { if let landscape = layout.landscapePositions { @@ -178,7 +188,7 @@ open class ContainerController: NSObject { self.controller = controller set(layout: layout) - NotificationCenter.default.addObserver(self, selector: #selector(rotated), name: UIDevice.orientationDidChangeNotification, object: nil) +// NotificationCenter.default.addObserver(self, selector: #selector(rotated), name: UIDevice.orientationDidChangeNotification, object: nil) createShadowButton() createContainerView() @@ -448,9 +458,29 @@ open class ContainerController: NSObject { } view.contentView?.addSubview(scrollView) +// scrollView.translatesAutoresizingMaskIntoConstraints = false +// scrollView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true +// scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true +// scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true +// scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true calculationViews() + + self.addRecognizerToScrollView(scrollView: scrollView) + } + + func addRecognizerToScrollView(scrollView: UIScrollView) { + if let panGesture = panGesture { + print("didScroll addRecognizer") + scrollView.addGestureRecognizer(panGesture) + } } + func removeRecognizerToScrollView(scrollView: UIScrollView) { + if let panGesture = panGesture { + print("didScroll removeRecognizer") + scrollView.removeGestureRecognizer(panGesture) + } + } // MARK: - Pan Gesture @objc private func handlePan(_ gesture: UIPanGestureRecognizer) { @@ -496,6 +526,14 @@ open class ContainerController: NSObject { move(type: type, animation: true, velocity: velocityY, from: .pan) + if type == .top && scrollView?.contentSize.height ?? 0.0 > (UIScreen.main.bounds.height * 0.95) { + + if let scrollView = self.scrollView { + self.removeRecognizerToScrollView(scrollView: scrollView) + + } + } + default: break } } @@ -756,7 +794,7 @@ open class ContainerController: NSObject { else { return positionMiddle } case .bottom: return positionBottom case .hide: return deviceHeight - case .custom: return 0.0 + case .custom: return positionCustom } } @@ -1266,6 +1304,10 @@ extension ContainerController: UIScrollViewDelegate { let from: ContainerFromType = .scrollBorder let animation = false + print("didScroll a \(position) \(type)") + + self.addRecognizerToScrollView(scrollView: scrollView) + shadowLevelAlpha(position: position, animation: false) changeFooterView(position: position) calculationScrollViewHeight(from: from) @@ -1301,12 +1343,16 @@ extension ContainerController: UIScrollViewDelegate { let from: ContainerFromType = .scroll let animation = false + print("didScroll b \(position) \(type)") + changeView(transform: scrollTransform) shadowLevelAlpha(position: position, animation: false) changeFooterView(position: position) calculationScrollViewHeight(from: from) changeMove(position: position, type: type, animation: animation) } + } else { + print("didScroll false") } } } diff --git a/Sources/ContainerController/ContainerControllerDelegate.swift b/Sources/ContainerController/ContainerControllerDelegate.swift index 8391e34..0611824 100644 --- a/Sources/ContainerController/ContainerControllerDelegate.swift +++ b/Sources/ContainerController/ContainerControllerDelegate.swift @@ -20,6 +20,8 @@ public protocol ContainerControllerDelegate { /// Reports the changes current position of the container, after its use func containerControllerMove(_ containerController: ContainerController, position: CGFloat, type: ContainerMoveType, animation: Bool) + func hideMenu(position: Double) + } @available(iOS 13.0, *) @@ -33,6 +35,9 @@ public extension ContainerControllerDelegate { } func containerControllerMove(_ containerController: ContainerController, position: CGFloat, type: ContainerMoveType, animation: Bool) { + + hideMenu(position: position) + } } diff --git a/Sources/ContainerController/ContainerDevice.swift b/Sources/ContainerController/ContainerDevice.swift index 7738823..e916ede 100644 --- a/Sources/ContainerController/ContainerDevice.swift +++ b/Sources/ContainerController/ContainerDevice.swift @@ -71,25 +71,7 @@ open class ContainerDevice { // MARK: - Orientation class public var isPortrait: Bool { - - var portrait: Bool = false - - let size: CGSize = UIScreen.main.bounds.size - if size.width / size.height > 1 { - portrait = false - } else { - portrait = true - } - - switch UIDevice.current.orientation { - case .landscapeLeft, .landscapeRight: - portrait = false - case .portrait: - portrait = true - default: break - } - - return portrait + return true } class var statusBarOrientation: UIInterfaceOrientation? { diff --git a/Sources/ContainerController/ContainerLayout.swift b/Sources/ContainerController/ContainerLayout.swift index 63e3de8..0b0f6c5 100644 --- a/Sources/ContainerController/ContainerLayout.swift +++ b/Sources/ContainerController/ContainerLayout.swift @@ -20,10 +20,13 @@ open class ContainerPosition { static let zero = ContainerPosition(top: 0, bottom: 0) - public init(top: CGFloat, middle: CGFloat? = nil, bottom: CGFloat) { + public var custom: CGFloat? + + public init(top: CGFloat, middle: CGFloat? = nil, bottom: CGFloat, custom: CGFloat? = nil) { self.top = top self.middle = middle self.bottom = bottom + self.custom = custom } }