Skip to content

Commit

Permalink
Merge pull request #19 from tamanyan/fix-layout
Browse files Browse the repository at this point in the history
Fix layout problem
  • Loading branch information
tamanyan authored Dec 14, 2018
2 parents 1b11c41 + 3f1f58f commit 0e5c2a9
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 34 deletions.
27 changes: 24 additions & 3 deletions PageMenuExample/PageMenuExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,13 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 0820;
LastUpgradeCheck = 1010;
ORGANIZATIONNAME = Tamanyan;
TargetAttributes = {
23C1D23A1E73099D00A4A491 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = 95Q9F9WGT3;
LastSwiftMigration = 1010;
ProvisioningStyle = Automatic;
};
};
Expand Down Expand Up @@ -259,15 +260,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -296,6 +305,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -309,15 +319,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand All @@ -338,6 +356,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -354,7 +373,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.tamanyan.SwiftPageMenu.PageMenuExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -369,7 +389,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.tamanyan.SwiftPageMenu.PageMenuExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
12 changes: 9 additions & 3 deletions PageMenuExample/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().barTintColor = Theme.mainColor
UINavigationBar.appearance().backgroundColor = Theme.mainColor
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
UINavigationBar.appearance().titleTextAttributes = convertToOptionalNSAttributedStringKeyDictionary([NSAttributedString.Key.foregroundColor.rawValue: UIColor.white])
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().shadowImage = UIImage()

self.window = UIWindow(frame: UIScreen.main.bounds)
let navController = UINavigationController(rootViewController: RootViewController())
if #available(iOS 11.0, *) {
navController.navigationBar.prefersLargeTitles = true
navController.navigationBar.largeTitleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
navController.navigationBar.largeTitleTextAttributes = convertToOptionalNSAttributedStringKeyDictionary([NSAttributedString.Key.foregroundColor.rawValue: UIColor.white])
}
self.window?.rootViewController = navController
self.window?.makeKeyAndVisible()
Expand Down Expand Up @@ -59,3 +59,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

}


// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertToOptionalNSAttributedStringKeyDictionary(_ input: [String: Any]?) -> [NSAttributedString.Key: Any]? {
guard let input = input else { return nil }
return Dictionary(uniqueKeysWithValues: input.map { key, value in (NSAttributedString.Key(rawValue: key), value)})
}
8 changes: 7 additions & 1 deletion PageMenuExample/Sources/PageTabMenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class PageTabMenuViewController: PageMenuController {

override func viewDidLoad() {
super.viewDidLoad()

self.edgesForExtendedLayout = []

if options.layout == .layoutGuide && options.tabMenuPosition == .bottom {
self.view.backgroundColor = Theme.mainColor
} else {
Expand All @@ -41,7 +43,11 @@ class PageTabMenuViewController: PageMenuController {
self.tabMenuView.heightAnchor.constraint(equalToConstant: self.options.menuItemSize.height).isActive = true
self.tabMenuView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
self.tabMenuView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
self.tabMenuView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
if #available(iOS 11.0, *) {
self.tabMenuView.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor).isActive = true
} else {
self.tabMenuView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
}
}

self.delegate = self
Expand Down
2 changes: 1 addition & 1 deletion PageMenuExample/Sources/UnderlinePagerOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct UnderlinePagerOption: PageMenuOptions {
var menuCursor: PageMenuCursor {
return .underline(barColor: Theme.mainColor, height: 2)
}

var font: UIFont {
return UIFont.systemFont(ofSize: UIFont.systemFontSize)
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/Enum/PageMenuOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public enum TabMenuPosition {
case custom
}

/**
The page menu layout.
If you use layoutGuide, page menu layout follow UILayoutGuide.
If you use edge, page menu layout follow edge (bottomAnchor, topAnchor)
*/
public enum PageMenuLayout {

case layoutGuide
Expand Down
13 changes: 7 additions & 6 deletions Sources/PageMenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit
open class PageMenuController: UIViewController {

/// SwiftPageMenu configurations
open let options: PageMenuOptions
public let options: PageMenuOptions

/// PageMenuController data source.
open weak var dataSource: PageMenuControllerDataSource? {
Expand Down Expand Up @@ -49,6 +49,7 @@ open class PageMenuController: UIViewController {
} else {
vc.automaticallyAdjustsScrollViewInsets = false
}

return vc
}()

Expand Down Expand Up @@ -252,7 +253,7 @@ open class PageMenuController: UIViewController {
}

fileprivate func setup() {
self.addChildViewController(self.pageViewController)
self.addChild(self.pageViewController)
self.view.addSubview(self.pageViewController.view)

switch self.options.tabMenuPosition {
Expand All @@ -276,10 +277,10 @@ open class PageMenuController: UIViewController {
switch self.options.layout {
case .layoutGuide:
if #available(iOS 11.0, *) {
self.pageViewController.view.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor).isActive = true
self.pageViewController.view.bottomAnchor.constraint(equalTo: self.bottomLayoutGuide.bottomAnchor).isActive = true
self.tabView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor).isActive = true
} else {
self.pageViewController.view.bottomAnchor.constraint(equalTo: self.bottomLayoutGuide.topAnchor).isActive = true
self.pageViewController.view.bottomAnchor.constraint(equalTo: self.bottomLayoutGuide.bottomAnchor).isActive = true
self.tabView.topAnchor.constraint(equalTo: self.topLayoutGuide.bottomAnchor).isActive = true
}
case .edge:
Expand Down Expand Up @@ -339,8 +340,8 @@ open class PageMenuController: UIViewController {
}
}

self.view.sendSubview(toBack: self.pageViewController.view)
self.pageViewController.didMove(toParentViewController: self)
self.view.sendSubviewToBack(self.pageViewController.view)
self.pageViewController.didMove(toParent: self)
}
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/TabMenu/TabMenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ extension TabMenuView {
currentCell.unHighlightTitle(progress: -1 * progress)
}

let width = fabs(progress) * (nextCell.frame.width - currentCell.frame.width)
let scroll = fabs(progress) * self.distance
let width = abs(progress) * (nextCell.frame.width - currentCell.frame.width)
let scroll = abs(progress) * self.distance

if self.isInfinite {
self.collectionView.contentOffset.x = (collectionViewContentOffsetX ?? 0) + scroll
Expand Down Expand Up @@ -356,7 +356,7 @@ extension TabMenuView {
fileprivate func deselectVisibleCells() {
self.collectionView
.visibleCells
.flatMap { $0 as? TabMenuItemCell }
.compactMap { $0 as? TabMenuItemCell }
.forEach {
$0.unHighlightTitle()
$0.isDecorationHidden = true
Expand All @@ -369,7 +369,7 @@ extension TabMenuView {
fileprivate func hiddenVisibleDecorations() {
self.collectionView
.visibleCells
.flatMap { $0 as? TabMenuItemCell }
.compactMap { $0 as? TabMenuItemCell }
.forEach { $0.isDecorationHidden = true }
}
}
Expand Down
20 changes: 10 additions & 10 deletions Sources/Util/EMPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -459,14 +459,14 @@ class EMPageViewController: UIViewController, UIScrollViewDelegate {

private func addChildIfNeeded(_ viewController: UIViewController) {
self.scrollView.addSubview(viewController.view)
self.addChildViewController(viewController)
viewController.didMove(toParentViewController: self)
self.addChild(viewController)
viewController.didMove(toParent: self)
}

private func removeChildIfNeeded(_ viewController: UIViewController?) {
viewController?.view.removeFromSuperview()
viewController?.didMove(toParentViewController: nil)
viewController?.removeFromParentViewController()
viewController?.didMove(toParent: nil)
viewController?.removeFromParent()
}

private func layoutViews() {
Expand All @@ -488,9 +488,9 @@ class EMPageViewController: UIViewController, UIScrollViewDelegate {
self.adjustingContentOffset = true
self.scrollView.contentOffset = CGPoint(x: self.isOrientationHorizontal ? viewWidth : 0, y: self.isOrientationHorizontal ? 0 : viewHeight)
if self.isOrientationHorizontal {
self.scrollView.contentInset = UIEdgeInsetsMake(0, beforeInset, 0, afterInset)
self.scrollView.contentInset = UIEdgeInsets.init(top: 0, left: beforeInset, bottom: 0, right: afterInset)
} else {
self.scrollView.contentInset = UIEdgeInsetsMake(beforeInset, 0, afterInset, 0)
self.scrollView.contentInset = UIEdgeInsets.init(top: beforeInset, left: 0, bottom: afterInset, right: 0)
}
self.adjustingContentOffset = false

Expand Down Expand Up @@ -639,14 +639,14 @@ class EMPageViewController: UIViewController, UIScrollViewDelegate {

if self.isOrientationHorizontal {
if (self.beforeViewController != nil && self.afterViewController != nil) || // It isn't at the beginning or end of the page collection
(self.afterViewController != nil && self.beforeViewController == nil && scrollView.contentOffset.x > fabs(scrollView.contentInset.left)) || // If it's at the beginning of the collection, the decelleration can't be triggered by scrolling away from, than torwards the inset
(self.beforeViewController != nil && self.afterViewController == nil && scrollView.contentOffset.x < fabs(scrollView.contentInset.right)) { // Same as the last condition, but at the end of the collection
(self.afterViewController != nil && self.beforeViewController == nil && scrollView.contentOffset.x > abs(scrollView.contentInset.left)) || // If it's at the beginning of the collection, the decelleration can't be triggered by scrolling away from, than torwards the inset
(self.beforeViewController != nil && self.afterViewController == nil && scrollView.contentOffset.x < abs(scrollView.contentInset.right)) { // Same as the last condition, but at the end of the collection
scrollView.setContentOffset(CGPoint(x: self.view.bounds.width, y: 0), animated: true)
}
} else {
if (self.beforeViewController != nil && self.afterViewController != nil) || // It isn't at the beginning or end of the page collection
(self.afterViewController != nil && self.beforeViewController == nil && scrollView.contentOffset.y > fabs(scrollView.contentInset.top)) || // If it's at the beginning of the collection, the decelleration can't be triggered by scrolling away from, than torwards the inset
(self.beforeViewController != nil && self.afterViewController == nil && scrollView.contentOffset.y < fabs(scrollView.contentInset.bottom)) { // Same as the last condition, but at the end of the collection
(self.afterViewController != nil && self.beforeViewController == nil && scrollView.contentOffset.y > abs(scrollView.contentInset.top)) || // If it's at the beginning of the collection, the decelleration can't be triggered by scrolling away from, than torwards the inset
(self.beforeViewController != nil && self.afterViewController == nil && scrollView.contentOffset.y < abs(scrollView.contentInset.bottom)) { // Same as the last condition, but at the end of the collection
scrollView.setContentOffset(CGPoint(x: 0, y: self.view.bounds.height), animated: true)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Util/PanBlockGestureRecognizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PanBlockGestureRecognizer: UIPanGestureRecognizer {
self.delegate = self.panBlockGestureRecognizerDelegate
}

func performAction(sender: UIGestureRecognizer) {
@objc func performAction(sender: UIGestureRecognizer) {
guard let panGesture = sender as? UIPanGestureRecognizer else { return }
let state = panGesture.state
let panLocation = panGesture.location(in: self.inView)
Expand All @@ -53,7 +53,7 @@ class PanBlockGestureRecognizer: UIPanGestureRecognizer {
let absY = abs(moveY)

if absY < permissionVertical && absX > swipeStroke {
panGesture.setValue(UIGestureRecognizerState.cancelled.rawValue, forKey: "state")
panGesture.setValue(UIGestureRecognizer.State.cancelled.rawValue, forKey: "state")
// self.isEnded = true
} else if absY > permissionVertical {
self.isEnded = true
Expand Down
Loading

0 comments on commit 0e5c2a9

Please sign in to comment.