Skip to content

Commit 0e5c2a9

Browse files
authored
Merge pull request #19 from tamanyan/fix-layout
Fix layout problem
2 parents 1b11c41 + 3f1f58f commit 0e5c2a9

File tree

11 files changed

+94
-34
lines changed

11 files changed

+94
-34
lines changed

PageMenuExample/PageMenuExample.xcodeproj/project.pbxproj

+24-3
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,13 @@
157157
isa = PBXProject;
158158
attributes = {
159159
LastSwiftUpdateCheck = 0820;
160-
LastUpgradeCheck = 0820;
160+
LastUpgradeCheck = 1010;
161161
ORGANIZATIONNAME = Tamanyan;
162162
TargetAttributes = {
163163
23C1D23A1E73099D00A4A491 = {
164164
CreatedOnToolsVersion = 8.2.1;
165165
DevelopmentTeam = 95Q9F9WGT3;
166+
LastSwiftMigration = 1010;
166167
ProvisioningStyle = Automatic;
167168
};
168169
};
@@ -259,15 +260,23 @@
259260
CLANG_CXX_LIBRARY = "libc++";
260261
CLANG_ENABLE_MODULES = YES;
261262
CLANG_ENABLE_OBJC_ARC = YES;
263+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
262264
CLANG_WARN_BOOL_CONVERSION = YES;
265+
CLANG_WARN_COMMA = YES;
263266
CLANG_WARN_CONSTANT_CONVERSION = YES;
267+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
264268
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
265269
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
266270
CLANG_WARN_EMPTY_BODY = YES;
267271
CLANG_WARN_ENUM_CONVERSION = YES;
268272
CLANG_WARN_INFINITE_RECURSION = YES;
269273
CLANG_WARN_INT_CONVERSION = YES;
274+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
275+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
276+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
270277
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
278+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
279+
CLANG_WARN_STRICT_PROTOTYPES = YES;
271280
CLANG_WARN_SUSPICIOUS_MOVE = YES;
272281
CLANG_WARN_UNREACHABLE_CODE = YES;
273282
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -296,6 +305,7 @@
296305
SDKROOT = iphoneos;
297306
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
298307
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
308+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
299309
TARGETED_DEVICE_FAMILY = "1,2";
300310
};
301311
name = Debug;
@@ -309,15 +319,23 @@
309319
CLANG_CXX_LIBRARY = "libc++";
310320
CLANG_ENABLE_MODULES = YES;
311321
CLANG_ENABLE_OBJC_ARC = YES;
322+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
312323
CLANG_WARN_BOOL_CONVERSION = YES;
324+
CLANG_WARN_COMMA = YES;
313325
CLANG_WARN_CONSTANT_CONVERSION = YES;
326+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
314327
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
315328
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
316329
CLANG_WARN_EMPTY_BODY = YES;
317330
CLANG_WARN_ENUM_CONVERSION = YES;
318331
CLANG_WARN_INFINITE_RECURSION = YES;
319332
CLANG_WARN_INT_CONVERSION = YES;
333+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
334+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
335+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
320336
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
337+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
338+
CLANG_WARN_STRICT_PROTOTYPES = YES;
321339
CLANG_WARN_SUSPICIOUS_MOVE = YES;
322340
CLANG_WARN_UNREACHABLE_CODE = YES;
323341
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -338,6 +356,7 @@
338356
MTL_ENABLE_DEBUG_INFO = NO;
339357
SDKROOT = iphoneos;
340358
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
359+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
341360
TARGETED_DEVICE_FAMILY = "1,2";
342361
VALIDATE_PRODUCT = YES;
343362
};
@@ -354,7 +373,8 @@
354373
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
355374
PRODUCT_BUNDLE_IDENTIFIER = com.tamanyan.SwiftPageMenu.PageMenuExample;
356375
PRODUCT_NAME = "$(TARGET_NAME)";
357-
SWIFT_VERSION = 3.0;
376+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
377+
SWIFT_VERSION = 4.2;
358378
};
359379
name = Debug;
360380
};
@@ -369,7 +389,8 @@
369389
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
370390
PRODUCT_BUNDLE_IDENTIFIER = com.tamanyan.SwiftPageMenu.PageMenuExample;
371391
PRODUCT_NAME = "$(TARGET_NAME)";
372-
SWIFT_VERSION = 3.0;
392+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
393+
SWIFT_VERSION = 4.2;
373394
};
374395
name = Release;
375396
};

PageMenuExample/Sources/AppDelegate.swift

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1313

1414
var window: UIWindow?
1515

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

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

6060
}
6161

62+
63+
// Helper function inserted by Swift 4.2 migrator.
64+
fileprivate func convertToOptionalNSAttributedStringKeyDictionary(_ input: [String: Any]?) -> [NSAttributedString.Key: Any]? {
65+
guard let input = input else { return nil }
66+
return Dictionary(uniqueKeysWithValues: input.map { key, value in (NSAttributedString.Key(rawValue: key), value)})
67+
}

PageMenuExample/Sources/PageTabMenuViewController.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class PageTabMenuViewController: PageMenuController {
2727

2828
override func viewDidLoad() {
2929
super.viewDidLoad()
30+
3031
self.edgesForExtendedLayout = []
32+
3133
if options.layout == .layoutGuide && options.tabMenuPosition == .bottom {
3234
self.view.backgroundColor = Theme.mainColor
3335
} else {
@@ -41,7 +43,11 @@ class PageTabMenuViewController: PageMenuController {
4143
self.tabMenuView.heightAnchor.constraint(equalToConstant: self.options.menuItemSize.height).isActive = true
4244
self.tabMenuView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
4345
self.tabMenuView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
44-
self.tabMenuView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
46+
if #available(iOS 11.0, *) {
47+
self.tabMenuView.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor).isActive = true
48+
} else {
49+
self.tabMenuView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
50+
}
4551
}
4652

4753
self.delegate = self

PageMenuExample/Sources/UnderlinePagerOption.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct UnderlinePagerOption: PageMenuOptions {
2828
var menuCursor: PageMenuCursor {
2929
return .underline(barColor: Theme.mainColor, height: 2)
3030
}
31-
31+
3232
var font: UIFont {
3333
return UIFont.systemFont(ofSize: UIFont.systemFontSize)
3434
}

Sources/Enum/PageMenuOptions.swift

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public enum TabMenuPosition {
6060
case custom
6161
}
6262

63+
/**
64+
The page menu layout.
65+
If you use layoutGuide, page menu layout follow UILayoutGuide.
66+
If you use edge, page menu layout follow edge (bottomAnchor, topAnchor)
67+
*/
6368
public enum PageMenuLayout {
6469

6570
case layoutGuide

Sources/PageMenuController.swift

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import UIKit
1111
open class PageMenuController: UIViewController {
1212

1313
/// SwiftPageMenu configurations
14-
open let options: PageMenuOptions
14+
public let options: PageMenuOptions
1515

1616
/// PageMenuController data source.
1717
open weak var dataSource: PageMenuControllerDataSource? {
@@ -49,6 +49,7 @@ open class PageMenuController: UIViewController {
4949
} else {
5050
vc.automaticallyAdjustsScrollViewInsets = false
5151
}
52+
5253
return vc
5354
}()
5455

@@ -252,7 +253,7 @@ open class PageMenuController: UIViewController {
252253
}
253254

254255
fileprivate func setup() {
255-
self.addChildViewController(self.pageViewController)
256+
self.addChild(self.pageViewController)
256257
self.view.addSubview(self.pageViewController.view)
257258

258259
switch self.options.tabMenuPosition {
@@ -276,10 +277,10 @@ open class PageMenuController: UIViewController {
276277
switch self.options.layout {
277278
case .layoutGuide:
278279
if #available(iOS 11.0, *) {
279-
self.pageViewController.view.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor).isActive = true
280+
self.pageViewController.view.bottomAnchor.constraint(equalTo: self.bottomLayoutGuide.bottomAnchor).isActive = true
280281
self.tabView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor).isActive = true
281282
} else {
282-
self.pageViewController.view.bottomAnchor.constraint(equalTo: self.bottomLayoutGuide.topAnchor).isActive = true
283+
self.pageViewController.view.bottomAnchor.constraint(equalTo: self.bottomLayoutGuide.bottomAnchor).isActive = true
283284
self.tabView.topAnchor.constraint(equalTo: self.topLayoutGuide.bottomAnchor).isActive = true
284285
}
285286
case .edge:
@@ -339,8 +340,8 @@ open class PageMenuController: UIViewController {
339340
}
340341
}
341342

342-
self.view.sendSubview(toBack: self.pageViewController.view)
343-
self.pageViewController.didMove(toParentViewController: self)
343+
self.view.sendSubviewToBack(self.pageViewController.view)
344+
self.pageViewController.didMove(toParent: self)
344345
}
345346
}
346347

Sources/TabMenu/TabMenuView.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ extension TabMenuView {
196196
currentCell.unHighlightTitle(progress: -1 * progress)
197197
}
198198

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

202202
if self.isInfinite {
203203
self.collectionView.contentOffset.x = (collectionViewContentOffsetX ?? 0) + scroll
@@ -356,7 +356,7 @@ extension TabMenuView {
356356
fileprivate func deselectVisibleCells() {
357357
self.collectionView
358358
.visibleCells
359-
.flatMap { $0 as? TabMenuItemCell }
359+
.compactMap { $0 as? TabMenuItemCell }
360360
.forEach {
361361
$0.unHighlightTitle()
362362
$0.isDecorationHidden = true
@@ -369,7 +369,7 @@ extension TabMenuView {
369369
fileprivate func hiddenVisibleDecorations() {
370370
self.collectionView
371371
.visibleCells
372-
.flatMap { $0 as? TabMenuItemCell }
372+
.compactMap { $0 as? TabMenuItemCell }
373373
.forEach { $0.isDecorationHidden = true }
374374
}
375375
}

Sources/Util/EMPageViewController.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -459,14 +459,14 @@ class EMPageViewController: UIViewController, UIScrollViewDelegate {
459459

460460
private func addChildIfNeeded(_ viewController: UIViewController) {
461461
self.scrollView.addSubview(viewController.view)
462-
self.addChildViewController(viewController)
463-
viewController.didMove(toParentViewController: self)
462+
self.addChild(viewController)
463+
viewController.didMove(toParent: self)
464464
}
465465

466466
private func removeChildIfNeeded(_ viewController: UIViewController?) {
467467
viewController?.view.removeFromSuperview()
468-
viewController?.didMove(toParentViewController: nil)
469-
viewController?.removeFromParentViewController()
468+
viewController?.didMove(toParent: nil)
469+
viewController?.removeFromParent()
470470
}
471471

472472
private func layoutViews() {
@@ -488,9 +488,9 @@ class EMPageViewController: UIViewController, UIScrollViewDelegate {
488488
self.adjustingContentOffset = true
489489
self.scrollView.contentOffset = CGPoint(x: self.isOrientationHorizontal ? viewWidth : 0, y: self.isOrientationHorizontal ? 0 : viewHeight)
490490
if self.isOrientationHorizontal {
491-
self.scrollView.contentInset = UIEdgeInsetsMake(0, beforeInset, 0, afterInset)
491+
self.scrollView.contentInset = UIEdgeInsets.init(top: 0, left: beforeInset, bottom: 0, right: afterInset)
492492
} else {
493-
self.scrollView.contentInset = UIEdgeInsetsMake(beforeInset, 0, afterInset, 0)
493+
self.scrollView.contentInset = UIEdgeInsets.init(top: beforeInset, left: 0, bottom: afterInset, right: 0)
494494
}
495495
self.adjustingContentOffset = false
496496

@@ -639,14 +639,14 @@ class EMPageViewController: UIViewController, UIScrollViewDelegate {
639639

640640
if self.isOrientationHorizontal {
641641
if (self.beforeViewController != nil && self.afterViewController != nil) || // It isn't at the beginning or end of the page collection
642-
(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
643-
(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
642+
(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
643+
(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
644644
scrollView.setContentOffset(CGPoint(x: self.view.bounds.width, y: 0), animated: true)
645645
}
646646
} else {
647647
if (self.beforeViewController != nil && self.afterViewController != nil) || // It isn't at the beginning or end of the page collection
648-
(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
649-
(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
648+
(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
649+
(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
650650
scrollView.setContentOffset(CGPoint(x: 0, y: self.view.bounds.height), animated: true)
651651
}
652652
}

Sources/Util/PanBlockGestureRecognizer.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class PanBlockGestureRecognizer: UIPanGestureRecognizer {
3535
self.delegate = self.panBlockGestureRecognizerDelegate
3636
}
3737

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

5555
if absY < permissionVertical && absX > swipeStroke {
56-
panGesture.setValue(UIGestureRecognizerState.cancelled.rawValue, forKey: "state")
56+
panGesture.setValue(UIGestureRecognizer.State.cancelled.rawValue, forKey: "state")
5757
// self.isEnded = true
5858
} else if absY > permissionVertical {
5959
self.isEnded = true

0 commit comments

Comments
 (0)