diff --git a/Sources/Pageboy.xcodeproj/project.pbxproj b/Sources/Pageboy.xcodeproj/project.pbxproj index 3bb42973..fe2a67e8 100644 --- a/Sources/Pageboy.xcodeproj/project.pbxproj +++ b/Sources/Pageboy.xcodeproj/project.pbxproj @@ -686,7 +686,7 @@ PRODUCT_NAME = Pageboy; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -704,7 +704,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.uias.Pageboy; PRODUCT_NAME = Pageboy; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/Sources/Pageboy/PageboyViewController+Management.swift b/Sources/Pageboy/PageboyViewController+Management.swift index 1cfddd50..4876dbb6 100644 --- a/Sources/Pageboy/PageboyViewController+Management.swift +++ b/Sources/Pageboy/PageboyViewController+Management.swift @@ -164,15 +164,27 @@ internal extension PageboyViewController { pageViewController.dataSource = self self.pageViewController = pageViewController + #if swift(>=4.2) addChild(pageViewController) + #else + addChildViewController(pageViewController) + #endif if let existingZIndex = existingZIndex { view.insertSubview(pageViewController.view, at: existingZIndex) } else { view.addSubview(pageViewController.view) + #if swift(>=4.2) view.sendSubviewToBack(pageViewController.view) + #else + view.sendSubview(toBack: pageViewController.view) + #endif } pageViewController.view.pinToSuperviewEdges() + #if swift(>=4.2) pageViewController.didMove(toParent: self) + #else + pageViewController.didMove(toParentViewController: self) + #endif pageViewController.scrollView?.delegate = self pageViewController.view.backgroundColor = .clear @@ -185,7 +197,11 @@ internal extension PageboyViewController { private func destroyCurrentPageViewController() { pageViewController?.view.removeFromSuperview() + #if swift(>=4.2) pageViewController?.removeFromParent() + #else + pageViewController?.removeFromParentViewController() + #endif pageViewController = nil } @@ -197,6 +213,7 @@ internal extension PageboyViewController { setUpPageViewController(reloadViewControllers: false) } + #if swift(>=4.2) /// The options to be passed to a UIPageViewController instance. internal var pageViewControllerOptions: [UIPageViewController.OptionsKey: Any]? { var options = [UIPageViewController.OptionsKey: Any]() @@ -210,6 +227,21 @@ internal extension PageboyViewController { } return options } + #else + /// The options to be passed to a UIPageViewController instance. + internal var pageViewControllerOptions: [String: Any]? { + var options = [String: Any]() + + if interPageSpacing > 0.0 { + options[UIPageViewControllerOptionInterPageSpacingKey] = interPageSpacing + } + + guard options.count > 0 else { + return nil + } + return options + } + #endif } // MARK: - UIPageViewControllerDataSource, PageboyViewControllerDataSource diff --git a/Sources/Pageboy/Transitioning/PageboyViewController+Transitioning.swift b/Sources/Pageboy/Transitioning/PageboyViewController+Transitioning.swift index 94278fc7..9533f08c 100644 --- a/Sources/Pageboy/Transitioning/PageboyViewController+Transitioning.swift +++ b/Sources/Pageboy/Transitioning/PageboyViewController+Transitioning.swift @@ -58,7 +58,11 @@ internal extension PageboyViewController { let displayLink = CADisplayLink(target: self, selector: #selector(displayLinkDidTick)) displayLink.isPaused = true + #if swift(>=4.2) displayLink.add(to: .main, forMode: .common) + #else + displayLink.add(to: .main, forMode: .commonModes) + #endif transitionDisplayLink = displayLink } @@ -156,6 +160,10 @@ internal extension PageboyViewController.Transition { func configure(transition: inout CATransition) { transition.duration = duration + #if swift(>=4.2) transition.type = CATransitionType(rawValue: style.rawValue) + #else + transition.type = style.rawValue + #endif } } diff --git a/Sources/Pageboy/Transitioning/TransitionOperation+Action.swift b/Sources/Pageboy/Transitioning/TransitionOperation+Action.swift index a1f97a10..8ca3bbcb 100644 --- a/Sources/Pageboy/Transitioning/TransitionOperation+Action.swift +++ b/Sources/Pageboy/Transitioning/TransitionOperation+Action.swift @@ -30,6 +30,7 @@ internal extension TransitionOperation { internal extension TransitionOperation.Action { + #if swift(>=4.2) /// Animation sub-type for the action. var transitionSubType: CATransitionSubtype { switch orientation { @@ -53,4 +54,29 @@ internal extension TransitionOperation.Action { } } } + #else + /// Animation sub-type for the action. + var transitionSubType: String { + switch orientation { + + case .horizontal: + switch semanticDirection { + + case .reverse: + return kCATransitionFromLeft + default: + return kCATransitionFromRight + } + + case .vertical: + switch semanticDirection { + + case .reverse: + return kCATransitionFromBottom + default: + return kCATransitionFromTop + } + } + } + #endif } diff --git a/Sources/Pageboy/Transitioning/TransitionOperation.swift b/Sources/Pageboy/Transitioning/TransitionOperation.swift index 6eb0328f..00ed4309 100644 --- a/Sources/Pageboy/Transitioning/TransitionOperation.swift +++ b/Sources/Pageboy/Transitioning/TransitionOperation.swift @@ -86,7 +86,11 @@ internal class TransitionOperation: NSObject, CAAnimationDelegate { animation.endProgress = 1.0 transition.configure(transition: &animation) animation.subtype = action.transitionSubType + #if swift(>=4.2) animation.fillMode = .backwards + #else + animation.fillMode = kCAFillModeBackwards + #endif self.animation = animation super.init()