From 717e3e270257fde90a64402d358def0e058479b8 Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Mon, 2 Oct 2017 22:20:41 +0200 Subject: [PATCH 1/7] Migrate the project to Swift 4 --- Cartfile | 2 +- Cartfile.resolved | 4 +- Presentation.xcodeproj/project.pbxproj | 22 +++++-- .../xcschemes/Presentation-iOS.xcscheme | 4 +- Source/Animations/Animatable.swift | 1 - Source/Animations/DissolveAnimation.swift | 30 +++++---- Source/Animations/PopAnimation.swift | 24 ++++---- Source/Animations/TransitionAnimation.swift | 41 +++++++------ Source/Content.swift | 22 +++---- Source/Extensions/CGPointExtension.swift | 1 - Source/Position.swift | 8 --- Source/PresentationController.swift | 61 +++++++++---------- Source/SlideController.swift | 20 +++--- 13 files changed, 123 insertions(+), 117 deletions(-) diff --git a/Cartfile b/Cartfile index aa7a1d9..8469903 100644 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1,2 @@ -github "hyperoslo/Pages" github "robb/Cartography" +github "hyperoslo/Pages" diff --git a/Cartfile.resolved b/Cartfile.resolved index 8741cfe..444a7d4 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ -github "robb/Cartography" "1.0.1" -github "hyperoslo/Pages" "1.0.0" +github "hyperoslo/Pages" "2.0.2" +github "robb/Cartography" "2.0.0" diff --git a/Presentation.xcodeproj/project.pbxproj b/Presentation.xcodeproj/project.pbxproj index e79c930..b10ca5b 100644 --- a/Presentation.xcodeproj/project.pbxproj +++ b/Presentation.xcodeproj/project.pbxproj @@ -154,12 +154,12 @@ D523B0C41C43AB90001AD1EC /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Hyper Interaktiv AS"; TargetAttributes = { D523B0CC1C43AB90001AD1EC = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; }; }; @@ -236,14 +236,20 @@ 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_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 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_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; @@ -286,14 +292,20 @@ 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_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 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_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; @@ -341,7 +353,8 @@ PRODUCT_BUNDLE_IDENTIFIER = no.hyper.Presentation; PRODUCT_NAME = Presentation; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -364,7 +377,8 @@ PRODUCT_BUNDLE_IDENTIFIER = no.hyper.Presentation; PRODUCT_NAME = Presentation; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/Presentation.xcodeproj/xcshareddata/xcschemes/Presentation-iOS.xcscheme b/Presentation.xcodeproj/xcshareddata/xcschemes/Presentation-iOS.xcscheme index 059292e..c7d182a 100644 --- a/Presentation.xcodeproj/xcshareddata/xcschemes/Presentation-iOS.xcscheme +++ b/Presentation.xcodeproj/xcshareddata/xcschemes/Presentation-iOS.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Source/Animations/Animatable.swift b/Source/Animations/Animatable.swift index 3524d45..018933e 100644 --- a/Source/Animations/Animatable.swift +++ b/Source/Animations/Animatable.swift @@ -1,7 +1,6 @@ import UIKit @objc public protocol Animatable { - func play() func playBack() func moveWith(offsetRatio: CGFloat) diff --git a/Source/Animations/DissolveAnimation.swift b/Source/Animations/DissolveAnimation.swift index 9b11e73..ddd03b6 100644 --- a/Source/Animations/DissolveAnimation.swift +++ b/Source/Animations/DissolveAnimation.swift @@ -1,15 +1,16 @@ import UIKit public class DissolveAnimation: NSObject, Animatable { + private let content: Content + private let duration: TimeInterval + private let delay: TimeInterval + private var initial: Bool + private var played = false - let content: Content - let duration: TimeInterval - let delay: TimeInterval - var initial: Bool - var played = false - - public init(content: Content, duration: TimeInterval = 1.0, - delay: TimeInterval = 0.0, initial: Bool = false) { + public init(content: Content, + duration: TimeInterval = 1.0, + delay: TimeInterval = 0.0, + initial: Bool = false) { self.content = content self.duration = duration self.delay = delay @@ -20,17 +21,20 @@ public class DissolveAnimation: NSObject, Animatable { super.init() } - fileprivate func animate() { + private func animate() { let alpha: CGFloat = content.view.alpha == 0.0 ? 1.0 : 0.0 - UIView.animate(withDuration: duration, + UIView.animate( + withDuration: duration, delay: delay, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.5, options: [.beginFromCurrentState, .allowUserInteraction], - animations: { [unowned self] in + animations: ({ [unowned self] in self.content.view.alpha = alpha - }, completion: nil) + }), + completion: nil + ) played = true } @@ -39,7 +43,6 @@ public class DissolveAnimation: NSObject, Animatable { // MARK: - Animatable extension DissolveAnimation { - public func play() { if content.view.superview != nil { if !(initial && played) { @@ -60,6 +63,7 @@ extension DissolveAnimation { public func moveWith(offsetRatio: CGFloat) { let view = content.view + if view.layer.animationKeys() == nil { if view.superview != nil { let ratio = offsetRatio > 0.0 ? offsetRatio : (1.0 + offsetRatio) diff --git a/Source/Animations/PopAnimation.swift b/Source/Animations/PopAnimation.swift index e71f316..6de84e1 100644 --- a/Source/Animations/PopAnimation.swift +++ b/Source/Animations/PopAnimation.swift @@ -1,11 +1,10 @@ import UIKit public class PopAnimation: NSObject, Animatable { - - let content: Content - let duration: TimeInterval - var initial: Bool - var played = false + private let content: Content + private let duration: TimeInterval + private var initial: Bool + private var played = false public init(content: Content, duration: TimeInterval = 1.0, initial: Bool = false) { self.content = content @@ -17,18 +16,20 @@ public class PopAnimation: NSObject, Animatable { super.init() } - fileprivate func animate() { + private func animate() { let view = content.view if view.isHidden { view.transform = CGAffineTransform(scaleX: 0.95, y: 0.95) } view.isHidden = false - UIView.animate(withDuration: duration, - animations: { + UIView.animate( + withDuration: duration, + animations: ({ view.transform = CGAffineTransform(scaleX: 1.05, y: 1.05) view.alpha = 0.8 - }, completion: { _ in + }), + completion: ({ _ in UIView.animate(withDuration: 0.1, animations: { view.transform = CGAffineTransform(scaleX: 0.95, y: 0.95) @@ -40,7 +41,8 @@ public class PopAnimation: NSObject, Animatable { view.alpha = 1.0 }, completion: nil) }) - }) + }) + ) played = true } @@ -49,7 +51,6 @@ public class PopAnimation: NSObject, Animatable { // MARK: - Animatable extension PopAnimation { - public func play() { if content.view.superview != nil { if !(initial && played) { @@ -70,6 +71,7 @@ extension PopAnimation { public func moveWith(offsetRatio: CGFloat) { let view = content.view + if view.layer.animationKeys() == nil { if view.superview != nil { let ratio = offsetRatio > 0.0 ? offsetRatio : (1.0 + offsetRatio) diff --git a/Source/Animations/TransitionAnimation.swift b/Source/Animations/TransitionAnimation.swift index da2bfaa..0fdae95 100644 --- a/Source/Animations/TransitionAnimation.swift +++ b/Source/Animations/TransitionAnimation.swift @@ -1,25 +1,28 @@ import UIKit public class TransitionAnimation: NSObject, Animatable { - - let content: Content - let destination: Position - let duration: TimeInterval - let damping: CGFloat + private let content: Content + private let destination: Position + private let duration: TimeInterval + private let damping: CGFloat var reflective: Bool - var initial: Bool - var played = false + private var initial: Bool + private var played = false lazy var start: Position = { [unowned self] in return self.content.position.positionCopy - }() + }() lazy var startMirror: Position = { [unowned self] in return self.start.horizontalMirror - }() - - public init(content: Content, destination: Position, - duration: TimeInterval = 1.0, damping: CGFloat = 0.7, reflective: Bool = false, initial: Bool = false) { + }() + + public init(content: Content, + destination: Position, + duration: TimeInterval = 1.0, + damping: CGFloat = 0.7, + reflective: Bool = false, + initial: Bool = false) { self.content = content self.destination = destination self.duration = duration @@ -30,16 +33,19 @@ public class TransitionAnimation: NSObject, Animatable { super.init() } - fileprivate func animate(to position: Position) { - UIView.animate(withDuration: duration, + private func animate(to position: Position) { + UIView.animate( + withDuration: duration, delay: 0, usingSpringWithDamping: damping, initialSpringVelocity: 0.5, options: [.beginFromCurrentState, .allowUserInteraction], - animations: { [unowned self] in + animations: ({ [unowned self] in self.content.position = position self.content.animate() - }, completion: nil) + }), + completion: nil + ) played = true } @@ -48,7 +54,6 @@ public class TransitionAnimation: NSObject, Animatable { // MARK: - Animatable extension TransitionAnimation { - public func play() { if let _ = content.view.superview { if !(initial && played) { @@ -63,7 +68,7 @@ extension TransitionAnimation { } public func playBack() { - if let _ = content.view.superview { + if content.view.superview != nil { if !(initial && played) { let position = reflective ? startMirror : start diff --git a/Source/Content.swift b/Source/Content.swift index 2804a86..dde84c1 100644 --- a/Source/Content.swift +++ b/Source/Content.swift @@ -2,7 +2,6 @@ import UIKit import Cartography public final class Content: NSObject { - public var view: UIView public var centered: Bool @@ -12,8 +11,8 @@ public final class Content: NSObject { } } - public fileprivate(set) var initialPosition: Position - fileprivate let group = ConstraintGroup() + public private(set) var initialPosition: Position + private let group = ConstraintGroup() public init(view: UIView, position: Position, centered: Bool = true) { self.view = view @@ -53,10 +52,8 @@ public final class Content: NSObject { } } -extension Content { - - public class func content(forTitle text: String, - attributes: [String : AnyObject]? = nil) -> Content { +public extension Content { + class func content(forTitle text: String, attributes: [NSAttributedStringKey: Any]? = nil) -> Content { let label = UILabel(frame: CGRect.zero) label.numberOfLines = 1 label.attributedText = NSAttributedString(string: text, attributes: attributes) @@ -67,8 +64,7 @@ extension Content { return Content(view: label, position: position) } - public class func content(forText text: String, - attributes: [String : AnyObject]? = nil) -> Content { + class func content(forText text: String, attributes: [NSAttributedStringKey: Any]? = nil) -> Content { let textView = UITextView(frame: CGRect.zero) textView.backgroundColor = UIColor.clear textView.attributedText = NSAttributedString(string: text, attributes: attributes) @@ -77,18 +73,18 @@ extension Content { return Content(view: textView, position: Position(left: 0.9, bottom: 0.1)) } - public class func content(forImage image: UIImage) -> Content { + class func content(forImage image: UIImage) -> Content { let imageView = UIImageView(image: image) - return Content(view: imageView, position: Position(left: 0.5, bottom: 0.5)) } - public class func centerTransition(forSlideContent content: Content) -> Animatable { + class func centerTransition(forSlideContent content: Content) -> Animatable { return TransitionAnimation( content: content, destination: Position(left: 0.5, bottom: content.initialPosition.bottom), duration: 2.0, damping: 0.8, - reflective: true) + reflective: true + ) } } diff --git a/Source/Extensions/CGPointExtension.swift b/Source/Extensions/CGPointExtension.swift index fff4758..35f48d1 100644 --- a/Source/Extensions/CGPointExtension.swift +++ b/Source/Extensions/CGPointExtension.swift @@ -1,7 +1,6 @@ import UIKit public extension CGPoint { - public func position(in frame: CGRect) -> Position { let left = x / frame.width let top = y / frame.height diff --git a/Source/Position.swift b/Source/Position.swift index c4c84ea..db2ef91 100644 --- a/Source/Position.swift +++ b/Source/Position.swift @@ -1,7 +1,6 @@ import UIKit @objc public class Position: NSObject { - public var left: CGFloat = 0.0 public var top: CGFloat = 0.0 @@ -25,28 +24,24 @@ import UIKit public init(left: CGFloat, top: CGFloat) { super.init() - self.left = left self.top = top } public init(left: CGFloat, bottom: CGFloat) { super.init() - self.left = left self.bottom = bottom } public init(right: CGFloat, top: CGFloat) { super.init() - self.right = right self.top = top } public init(right: CGFloat, bottom: CGFloat) { super.init() - self.right = right self.bottom = bottom } @@ -65,19 +60,16 @@ import UIKit public func xInFrame(_ frame: CGRect) -> CGFloat { let margin = frame.width * left - return frame.minX + margin } public func yInFrame(_ frame: CGRect) -> CGFloat { let margin = frame.height * top - return frame.minY + margin } public func isEqualTo(position: Position, epsilon: CGFloat = 0.0001) -> Bool { let dx = left - position.left, dy = top - position.top - return (dx * dx + dy * dy) < epsilon } } diff --git a/Source/PresentationController.swift b/Source/PresentationController.swift index 91135c6..cb0ae89 100644 --- a/Source/PresentationController.swift +++ b/Source/PresentationController.swift @@ -2,31 +2,31 @@ import UIKit import Pages @objc public protocol PresentationControllerDelegate { - func presentationController( _ presentationController: PresentationController, didSetViewController viewController: UIViewController, - atPage page: Int) + atPage page: Int + ) } open class PresentationController: PagesController { + public weak var presentationDelegate: PresentationControllerDelegate? + public var maxAnimationDelay: Double = 3 - open weak var presentationDelegate: PresentationControllerDelegate? - open var maxAnimationDelay: Double = 3 - - fileprivate var backgroundContents = [Content]() - fileprivate var slides = [SlideController]() - fileprivate var animationsForPages = [Int : [Animatable]]() + private var backgroundContents = [Content]() + private var slides = [SlideController]() + private var animationsForPages = [Int : [Animatable]]() - fileprivate var animationIndex = 0 - fileprivate weak var scrollView: UIScrollView? - var animationTimer: Timer? + private var animationIndex = 0 + private weak var scrollView: UIScrollView? + private var animationTimer: Timer? public convenience init(pages: [UIViewController]) { self.init( transitionStyle: .scroll, navigationOrientation: .horizontal, - options: nil) + options: nil + ) add(pages) } @@ -35,7 +35,6 @@ open class PresentationController: PagesController { open override func viewDidLoad() { pagesDelegate = self - super.viewDidLoad() } @@ -89,9 +88,10 @@ open class PresentationController: PagesController { // MARK: - Animation Timer - func startAnimationTimer() { + private func startAnimationTimer() { stopAnimationTimer() scrollView?.isUserInteractionEnabled = false + if animationTimer == nil { DispatchQueue.main.async { self.animationTimer = Timer.scheduledTimer(timeInterval: self.maxAnimationDelay, @@ -104,20 +104,17 @@ open class PresentationController: PagesController { } } - func stopAnimationTimer() { + private func stopAnimationTimer() { animationTimer?.invalidate() animationTimer = nil } - func updateAnimationTimer(_ timer: Timer) { + @objc func updateAnimationTimer(_ timer: Timer) { stopAnimationTimer() scrollView?.isUserInteractionEnabled = true } -} - -// MARK: - Content -extension PresentationController { + // MARK: - Content open override func add(_ viewControllers: [UIViewController]) { for case let controller as SlideController in viewControllers { @@ -139,7 +136,6 @@ extension PresentationController { // MARK: - Animations extension PresentationController { - public func addAnimations(_ animations: [Animatable], forPage page: Int) { for animation in animations { addAnimation(animation, forPage: page) @@ -153,7 +149,7 @@ extension PresentationController { animationsForPages[page]?.append(animation) } - fileprivate func animateAtIndex(_ index: Int, perform: (_ animation: Animatable) -> Void) { + private func animateAtIndex(_ index: Int, perform: (_ animation: Animatable) -> Void) { if let animations = animationsForPages[index] { for animation in animations { perform(animation) @@ -165,27 +161,28 @@ extension PresentationController { // MARK: - PagesControllerDelegate extension PresentationController: PagesControllerDelegate { - open func pageViewController(_ pageViewController: UIPageViewController, - setViewController viewController: UIViewController, atPage page: Int) { - animationIndex = page - scrollView?.delegate = self - - presentationDelegate?.presentationController(self, - didSetViewController: viewController, - atPage: page) + setViewController viewController: UIViewController, + atPage page: Int) { + animationIndex = page + scrollView?.delegate = self + + presentationDelegate?.presentationController( + self, + didSetViewController: viewController, + atPage: page + ) } } // MARK: - UIScrollViewDelegate extension PresentationController: UIScrollViewDelegate { - open func scrollViewDidScroll(_ scrollView: UIScrollView) { let offset = scrollView.contentOffset.x - (view.frame).width let offsetRatio = offset / (view.frame).width - var index = animationIndex + if offsetRatio > 0.0 || index == 0 { index += 1 } diff --git a/Source/SlideController.swift b/Source/SlideController.swift index 6e1f881..c44c1ab 100644 --- a/Source/SlideController.swift +++ b/Source/SlideController.swift @@ -1,14 +1,12 @@ import UIKit open class SlideController: UIViewController { - - fileprivate var contents = [Content]() - fileprivate var animations = [Animatable]() - fileprivate var visible = false + private var contents = [Content]() + private var animations = [Animatable]() + private var visible = false public convenience init(contents: [Content]) { self.init() - add(contents: contents) } @@ -31,7 +29,6 @@ open class SlideController: UIViewController { open override func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) - visible = false } @@ -52,28 +49,27 @@ open class SlideController: UIViewController { // MARK: - Public methods -extension SlideController { - - public func add(contents: [Content]) { +public extension SlideController { + func add(contents: [Content]) { for content in contents { add(content: content) } } - public func add(content: Content) { + func add(content: Content) { contents.append(content) view.addSubview(content.view) content.layout() } - public func add(animations: [Animatable]) { + func add(animations: [Animatable]) { for animation in animations { add(animation: animation) } } - public func add(animation: Animatable) { + func add(animation: Animatable) { animations.append(animation) } } From d4fcc66f6fae665e6dfad090c6aaa3bf2f182857 Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Mon, 2 Oct 2017 22:28:22 +0200 Subject: [PATCH 2/7] Refactor source code --- Source/Content.swift | 56 +++++++++++++----------- Source/Extensions/CGPointExtension.swift | 1 - Source/SlideController.swift | 1 - 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/Source/Content.swift b/Source/Content.swift index dde84c1..f271272 100644 --- a/Source/Content.swift +++ b/Source/Content.swift @@ -29,22 +29,28 @@ public final class Content: NSObject { } public func layout() { - if let _ = view.superview { - constrain(view, replace: group) { [unowned self] view in - let x = self.position.left == 0.0 ? view.superview!.left * 1.0 : - view.superview!.right * self.position.left - let y = self.position.top == 0.0 ? view.superview!.top * 1.0 : - view.superview!.bottom * self.position.top - if self.centered { - view.centerX == x - view.centerY == y - } else { - view.left == x - view.top == y - } + guard view.superview != nil else { + return + } + + constrain(view, replace: group) { [unowned self] view in + let x = self.position.left == 0.0 + ? view.superview!.left * 1.0 + : view.superview!.right * self.position.left + let y = self.position.top == 0.0 + ? view.superview!.top * 1.0 + : view.superview!.bottom * self.position.top + + if self.centered { + view.centerX == x + view.centerY == y + } else { + view.left == x + view.top == y } - view.layoutIfNeeded() } + + view.layoutIfNeeded() } public func animate() { @@ -54,23 +60,23 @@ public final class Content: NSObject { public extension Content { class func content(forTitle text: String, attributes: [NSAttributedStringKey: Any]? = nil) -> Content { - let label = UILabel(frame: CGRect.zero) - label.numberOfLines = 1 - label.attributedText = NSAttributedString(string: text, attributes: attributes) - label.sizeToFit() + let label = UILabel(frame: CGRect.zero) + label.numberOfLines = 1 + label.attributedText = NSAttributedString(string: text, attributes: attributes) + label.sizeToFit() - let position = Position(left: 0.9, bottom: 0.2) + let position = Position(left: 0.9, bottom: 0.2) - return Content(view: label, position: position) + return Content(view: label, position: position) } class func content(forText text: String, attributes: [NSAttributedStringKey: Any]? = nil) -> Content { - let textView = UITextView(frame: CGRect.zero) - textView.backgroundColor = UIColor.clear - textView.attributedText = NSAttributedString(string: text, attributes: attributes) - textView.sizeToFit() + let textView = UITextView(frame: CGRect.zero) + textView.backgroundColor = UIColor.clear + textView.attributedText = NSAttributedString(string: text, attributes: attributes) + textView.sizeToFit() - return Content(view: textView, position: Position(left: 0.9, bottom: 0.1)) + return Content(view: textView, position: Position(left: 0.9, bottom: 0.1)) } class func content(forImage image: UIImage) -> Content { diff --git a/Source/Extensions/CGPointExtension.swift b/Source/Extensions/CGPointExtension.swift index 35f48d1..2c73bd7 100644 --- a/Source/Extensions/CGPointExtension.swift +++ b/Source/Extensions/CGPointExtension.swift @@ -4,7 +4,6 @@ public extension CGPoint { public func position(in frame: CGRect) -> Position { let left = x / frame.width let top = y / frame.height - return Position(left: left, top: top) } } diff --git a/Source/SlideController.swift b/Source/SlideController.swift index c44c1ab..73aff2c 100644 --- a/Source/SlideController.swift +++ b/Source/SlideController.swift @@ -59,7 +59,6 @@ public extension SlideController { func add(content: Content) { contents.append(content) view.addSubview(content.view) - content.layout() } From 4cf30400814cf6935d59db5b3e71e50e0310ef47 Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Mon, 2 Oct 2017 22:44:36 +0200 Subject: [PATCH 3/7] Update tutorial framework --- .swift-version | 2 +- Example/Tutorial/.swift-version | 1 + Example/Tutorial/Podfile | 8 ++--- Example/Tutorial/Podfile.lock | 28 ++++++--------- .../Tutorial.xcodeproj/project.pbxproj | 36 ++++++++++++++++--- Example/Tutorial/Tutorial/AppDelegate.swift | 21 ++++++----- 6 files changed, 57 insertions(+), 39 deletions(-) create mode 100644 Example/Tutorial/.swift-version diff --git a/.swift-version b/.swift-version index 9f55b2c..5186d07 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -3.0 +4.0 diff --git a/Example/Tutorial/.swift-version b/Example/Tutorial/.swift-version new file mode 100644 index 0000000..5186d07 --- /dev/null +++ b/Example/Tutorial/.swift-version @@ -0,0 +1 @@ +4.0 diff --git a/Example/Tutorial/Podfile b/Example/Tutorial/Podfile index 1bf327b..28d416e 100644 --- a/Example/Tutorial/Podfile +++ b/Example/Tutorial/Podfile @@ -4,7 +4,7 @@ use_frameworks! platform :ios, '8.0' -target 'Tutorial' do - pod 'Presentation', path: '../../' - pod 'Hue', git: 'https://github.com/hyperoslo/Hue', branch: 'swift3' -end +pod 'Presentation', path: '../../' +pod 'Hue' + +target 'Tutorial' diff --git a/Example/Tutorial/Podfile.lock b/Example/Tutorial/Podfile.lock index 91661f1..603396a 100644 --- a/Example/Tutorial/Podfile.lock +++ b/Example/Tutorial/Podfile.lock @@ -1,33 +1,25 @@ PODS: - - Cartography (1.0.1) + - Cartography (2.0.0) - Hue (1.2.0) - - Pages (1.0.0) - - Presentation (3.0.0): + - Pages (2.0.2) + - Presentation (3.1.0): - Cartography - Pages DEPENDENCIES: - - Hue (from `https://github.com/hyperoslo/Hue`, branch `swift3`) + - Hue - Presentation (from `../../`) EXTERNAL SOURCES: - Hue: - :branch: swift3 - :git: https://github.com/hyperoslo/Hue Presentation: - :path: "../../" - -CHECKOUT OPTIONS: - Hue: - :commit: 3303cbcdf0f771aea1a6d1a153e4b95eef8696eb - :git: https://github.com/hyperoslo/Hue + :path: ../../ SPEC CHECKSUMS: - Cartography: c1460e99395b824d9d75360b0382faeb0b33dcd7 + Cartography: d295eb25ab54bb57eecd8c2f04e9648c850f1281 Hue: 0705083b7aff40334033373e6293ec1215285ac2 - Pages: f3718e6f03a5e2787f6b0bff4becb3c7c19bcebc - Presentation: 2a7e0379ab403c0bd91c4f6d5c59480edba6f429 + Pages: 5564ac6035c48fef7a837049314f57507d263b11 + Presentation: 07f001419368d0ece73285f238b1dc3852462f23 -PODFILE CHECKSUM: a46ef067438fe85dbabc3ca50d68bda71f1ff526 +PODFILE CHECKSUM: a2be853ebf7792783dc915c68a50d0f469a3c2ec -COCOAPODS: 1.2.0 +COCOAPODS: 1.3.1 diff --git a/Example/Tutorial/Tutorial.xcodeproj/project.pbxproj b/Example/Tutorial/Tutorial.xcodeproj/project.pbxproj index 02e95d9..d2f8213 100644 --- a/Example/Tutorial/Tutorial.xcodeproj/project.pbxproj +++ b/Example/Tutorial/Tutorial.xcodeproj/project.pbxproj @@ -122,12 +122,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = Hyper; TargetAttributes = { D54221851AF64A7000F4E9A8 = { CreatedOnToolsVersion = 6.3.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; }; }; @@ -168,13 +168,16 @@ files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Tutorial-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; 8058477F6FC36BF93DD6D31F /* [CP] Copy Pods Resources */ = { @@ -198,9 +201,18 @@ files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-Tutorial/Pods-Tutorial-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/Cartography/Cartography.framework", + "${BUILT_PRODUCTS_DIR}/Hue/Hue.framework", + "${BUILT_PRODUCTS_DIR}/Pages/Pages.framework", + "${BUILT_PRODUCTS_DIR}/Presentation/Presentation.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Cartography.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Hue.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Pages.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Presentation.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -240,14 +252,20 @@ 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_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 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_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; @@ -288,14 +306,20 @@ 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_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 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_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; @@ -331,7 +355,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "no.hyper.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = Tutorial; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -346,7 +371,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "no.hyper.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = Tutorial; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/Example/Tutorial/Tutorial/AppDelegate.swift b/Example/Tutorial/Tutorial/AppDelegate.swift index 25832cd..7cc4611 100644 --- a/Example/Tutorial/Tutorial/AppDelegate.swift +++ b/Example/Tutorial/Tutorial/AppDelegate.swift @@ -4,36 +4,35 @@ import Presentation @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { - var window: UIWindow? lazy var navigationController: UINavigationController = { [unowned self] in let controller = UINavigationController(rootViewController: self.presentationController) controller.view.backgroundColor = UIColor(hex:"FF5703") - return controller }() lazy var presentationController: PresentationController = { let controller = PresentationController(pages: []) controller.setNavigationTitle = false - return controller - }() + }() lazy var leftButton: UIBarButtonItem = { [unowned self] in let button = UIBarButtonItem( title: "Previous page", style: .plain, target: self.presentationController, - action: #selector(PresentationController.moveBack)) + action: #selector(PresentationController.moveBack) + ) button.setTitleTextAttributes( - [NSForegroundColorAttributeName : UIColor.white], - for: .normal) + [NSAttributedStringKey.foregroundColor: UIColor.white], + for: .normal + ) return button - }() + }() lazy var rightButton: UIBarButtonItem = { [unowned self] in let button = UIBarButtonItem( @@ -43,7 +42,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { action: #selector(PresentationController.moveForward)) button.setTitleTextAttributes( - [NSForegroundColorAttributeName : UIColor.white], + [NSAttributedStringKey.foregroundColor: UIColor.white], for: .normal) return button @@ -76,8 +75,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.alignment = .center - let attributes = [NSFontAttributeName: font, NSForegroundColorAttributeName: color, - NSParagraphStyleAttributeName: paragraphStyle] + let attributes = [NSAttributedStringKey.font: font, NSAttributedStringKey.foregroundColor: color, + NSAttributedStringKey.paragraphStyle: paragraphStyle] let titles = ["Tutorial on how to make a profit", "Step I", "Step II", "Step III", "Thanks"].map { Content.content(forTitle: $0, attributes: attributes) From 7f4a6a396ea3ed699cfad90ba6f2fa4da50a41d1 Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Mon, 2 Oct 2017 22:58:52 +0200 Subject: [PATCH 4/7] Refactor Parallax demo --- Example/Parallax/.swift-version | 1 + .../Parallax.xcodeproj/project.pbxproj | 36 +++++++++++-- Example/Parallax/Parallax/AppDelegate.swift | 20 +++---- .../Parallax/Parallax/ViewController.swift | 52 +++++++++++-------- Example/Parallax/Podfile | 8 +-- Example/Parallax/Podfile.lock | 32 +++++------- Example/Tutorial/Tutorial/AppDelegate.swift | 46 ++++++++-------- 7 files changed, 105 insertions(+), 90 deletions(-) create mode 100644 Example/Parallax/.swift-version diff --git a/Example/Parallax/.swift-version b/Example/Parallax/.swift-version new file mode 100644 index 0000000..5186d07 --- /dev/null +++ b/Example/Parallax/.swift-version @@ -0,0 +1 @@ +4.0 diff --git a/Example/Parallax/Parallax.xcodeproj/project.pbxproj b/Example/Parallax/Parallax.xcodeproj/project.pbxproj index bb57435..a32dd05 100644 --- a/Example/Parallax/Parallax.xcodeproj/project.pbxproj +++ b/Example/Parallax/Parallax.xcodeproj/project.pbxproj @@ -133,12 +133,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = Hyper; TargetAttributes = { D563C9F51AF6DD6400E2F7C8 = { CreatedOnToolsVersion = 6.3.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; }; }; @@ -179,13 +179,16 @@ files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Parallax-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; 513D09C629696FF9539C0C6E /* [CP] Copy Pods Resources */ = { @@ -209,9 +212,18 @@ files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-Parallax/Pods-Parallax-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/Cartography/Cartography.framework", + "${BUILT_PRODUCTS_DIR}/Hue/Hue.framework", + "${BUILT_PRODUCTS_DIR}/Pages/Pages.framework", + "${BUILT_PRODUCTS_DIR}/Presentation/Presentation.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Cartography.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Hue.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Pages.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Presentation.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -252,14 +264,20 @@ 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_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 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_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; @@ -301,14 +319,20 @@ 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_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 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_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; @@ -345,7 +369,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "no.hyper.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -360,7 +385,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "no.hyper.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/Example/Parallax/Parallax/AppDelegate.swift b/Example/Parallax/Parallax/AppDelegate.swift index abfe19e..f3fde37 100644 --- a/Example/Parallax/Parallax/AppDelegate.swift +++ b/Example/Parallax/Parallax/AppDelegate.swift @@ -2,23 +2,15 @@ import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { - var window: UIWindow? - lazy var navigationController: UINavigationController = { [unowned self] in - let controller = UINavigationController(rootViewController: self.presentationController) - - return controller - }() - - lazy var presentationController: ViewController = { - return ViewController(pages: []) - }() - - func application( - _ application: UIApplication, - didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + private lazy var navigationController: UINavigationController = .init( + rootViewController: self.presentationController + ) + private lazy var presentationController: ViewController = .init(pages: []) + func application(_ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default) UINavigationBar.appearance().barStyle = .default UINavigationBar.appearance().shadowImage = UIImage() diff --git a/Example/Parallax/Parallax/ViewController.swift b/Example/Parallax/Parallax/ViewController.swift index 574d304..994642a 100644 --- a/Example/Parallax/Parallax/ViewController.swift +++ b/Example/Parallax/Parallax/ViewController.swift @@ -3,8 +3,7 @@ import Hue import Presentation class ViewController: PresentationController { - - struct BackgroundImage { + private struct BackgroundImage { let name: String let left: CGFloat let top: CGFloat @@ -29,7 +28,7 @@ class ViewController: PresentationController { } } - lazy var leftButton: UIBarButtonItem = { [unowned self] in + private lazy var leftButton: UIBarButtonItem = { [unowned self] in let leftButton = UIBarButtonItem( title: "Previous", style: .plain, @@ -37,25 +36,28 @@ class ViewController: PresentationController { action: #selector(moveBack)) leftButton.setTitleTextAttributes( - [NSForegroundColorAttributeName : UIColor.black], - for: .normal) + [NSAttributedStringKey.foregroundColor : UIColor.black], + for: .normal + ) return leftButton - }() + }() - lazy var rightButton: UIBarButtonItem = { [unowned self] in + private lazy var rightButton: UIBarButtonItem = { [unowned self] in let rightButton = UIBarButtonItem( title: "Next", style: .plain, target: self, - action: #selector(moveForward)) + action: #selector(moveForward) + ) rightButton.setTitleTextAttributes( - [NSForegroundColorAttributeName : UIColor.black], - for: .normal) + [NSAttributedStringKey.foregroundColor : UIColor.black], + for: .normal + ) return rightButton - }() + }() override func viewDidLoad() { super.viewDidLoad() @@ -63,7 +65,6 @@ class ViewController: PresentationController { setNavigationTitle = false navigationItem.leftBarButtonItem = leftButton navigationItem.rightBarButtonItem = rightButton - view.backgroundColor = UIColor(hex: "FFBC00") configureSlides() @@ -72,15 +73,18 @@ class ViewController: PresentationController { // MARK: - Configuration - func configureSlides() { + private func configureSlides() { let ratio: CGFloat = UIDevice.current.userInterfaceIdiom == .pad ? 1 : 0.6 let font = UIFont(name: "HelveticaNeue", size: 34.0 * ratio)! let color = UIColor(hex: "FFE8A9") let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.alignment = NSTextAlignment.center - let attributes = [NSFontAttributeName: font, NSForegroundColorAttributeName: color, - NSParagraphStyleAttributeName: paragraphStyle] + let attributes = [ + NSAttributedStringKey.font: font, + NSAttributedStringKey.foregroundColor: color, + NSAttributedStringKey.paragraphStyle: paragraphStyle + ] let titles = [ "Parallax is a displacement or difference in the apparent position of an object viewed along two different lines of sight.", @@ -101,14 +105,13 @@ class ViewController: PresentationController { for index in 0...4 { let controller = SlideController(contents: [titles[index]]) controller.add(animations: [Content.centerTransition(forSlideContent: titles[index])]) - slides.append(controller) } add(slides) } - func configureBackground() { + private func configureBackground() { let backgroundImages = [ BackgroundImage(name: "Trees", left: 0.0, top: 0.743, speed: -0.3), BackgroundImage(name: "Bus", left: 0.02, top: 0.77, speed: 0.25), @@ -136,23 +139,26 @@ class ViewController: PresentationController { for (column, backgroundImage) in backgroundImages.enumerated() { if let position = backgroundImage.positionAt(row), let content = contents.at(column) { addAnimation(TransitionAnimation(content: content, destination: position, - duration: 2.0, damping: 1.0), forPage: row) + duration: 2.0, damping: 1.0), forPage: row) } } } let groundView = UIView(frame: CGRect(x: 0, y: 0, width: 1024, height: 60)) groundView.backgroundColor = UIColor(hex: "FFCD41") - let groundContent = Content(view: groundView, - position: Position(left: 0.0, bottom: 0.063), centered: false) - contents.append(groundContent) + let groundContent = Content( + view: groundView, + position: Position(left: 0.0, bottom: 0.063), + centered: false + ) + + contents.append(groundContent) addToBackground([groundContent]) } } -extension Array { - +private extension Array { func at(_ index: Int?) -> Element? { var object: Element? if let index = index , index >= 0 && index < endIndex { diff --git a/Example/Parallax/Podfile b/Example/Parallax/Podfile index 1c64805..856af66 100644 --- a/Example/Parallax/Podfile +++ b/Example/Parallax/Podfile @@ -2,7 +2,7 @@ use_frameworks! platform :ios, '8.0' -target 'Parallax' do - pod 'Presentation', path: '../../' - pod 'Hue', git: 'https://github.com/hyperoslo/Hue', branch: 'swift3' -end +pod 'Presentation', path: '../../' +pod 'Hue' + +target 'Parallax' diff --git a/Example/Parallax/Podfile.lock b/Example/Parallax/Podfile.lock index e5c7aba..719542b 100644 --- a/Example/Parallax/Podfile.lock +++ b/Example/Parallax/Podfile.lock @@ -1,33 +1,25 @@ PODS: - - Cartography (1.0.1) - - Hue (1.2.0) - - Pages (1.0.0) - - Presentation (3.0.0): + - Cartography (2.0.0) + - Hue (2.0.1) + - Pages (2.0.2) + - Presentation (3.1.0): - Cartography - Pages DEPENDENCIES: - - Hue (from `https://github.com/hyperoslo/Hue`, branch `swift3`) + - Hue - Presentation (from `../../`) EXTERNAL SOURCES: - Hue: - :branch: swift3 - :git: https://github.com/hyperoslo/Hue Presentation: - :path: "../../" - -CHECKOUT OPTIONS: - Hue: - :commit: 3303cbcdf0f771aea1a6d1a153e4b95eef8696eb - :git: https://github.com/hyperoslo/Hue + :path: ../../ SPEC CHECKSUMS: - Cartography: c1460e99395b824d9d75360b0382faeb0b33dcd7 - Hue: 0705083b7aff40334033373e6293ec1215285ac2 - Pages: f3718e6f03a5e2787f6b0bff4becb3c7c19bcebc - Presentation: 2a7e0379ab403c0bd91c4f6d5c59480edba6f429 + Cartography: d295eb25ab54bb57eecd8c2f04e9648c850f1281 + Hue: 354caec055fdc9d38b5ef33ca2e7224721843baf + Pages: 5564ac6035c48fef7a837049314f57507d263b11 + Presentation: 07f001419368d0ece73285f238b1dc3852462f23 -PODFILE CHECKSUM: f41db61a2828ca5a77fd53546b00649e4bd644cc +PODFILE CHECKSUM: 8a38e1ff9630071a018856bbaebe49be27870e49 -COCOAPODS: 1.2.0 +COCOAPODS: 1.3.1 diff --git a/Example/Tutorial/Tutorial/AppDelegate.swift b/Example/Tutorial/Tutorial/AppDelegate.swift index 7cc4611..690fcb1 100644 --- a/Example/Tutorial/Tutorial/AppDelegate.swift +++ b/Example/Tutorial/Tutorial/AppDelegate.swift @@ -6,19 +6,19 @@ import Presentation class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - lazy var navigationController: UINavigationController = { [unowned self] in + private lazy var navigationController: UINavigationController = { [unowned self] in let controller = UINavigationController(rootViewController: self.presentationController) controller.view.backgroundColor = UIColor(hex:"FF5703") return controller }() - lazy var presentationController: PresentationController = { + private lazy var presentationController: PresentationController = { let controller = PresentationController(pages: []) controller.setNavigationTitle = false return controller }() - lazy var leftButton: UIBarButtonItem = { [unowned self] in + private lazy var leftButton: UIBarButtonItem = { [unowned self] in let button = UIBarButtonItem( title: "Previous page", style: .plain, @@ -34,41 +34,41 @@ class AppDelegate: UIResponder, UIApplicationDelegate { return button }() - lazy var rightButton: UIBarButtonItem = { [unowned self] in + private lazy var rightButton: UIBarButtonItem = { [unowned self] in let button = UIBarButtonItem( title: "Next page", style: .plain, target: self.presentationController, - action: #selector(PresentationController.moveForward)) + action: #selector(PresentationController.moveForward) + ) button.setTitleTextAttributes( [NSAttributedStringKey.foregroundColor: UIColor.white], - for: .normal) + for: .normal + ) return button }() - func application( - _ application: UIApplication, - didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + UINavigationBar.appearance().barTintColor = UIColor(hex: "FF5703") + UINavigationBar.appearance().barStyle = .blackTranslucent - UINavigationBar.appearance().barTintColor = UIColor(hex: "FF5703") - UINavigationBar.appearance().barStyle = .blackTranslucent + presentationController.navigationItem.leftBarButtonItem = leftButton + presentationController.navigationItem.rightBarButtonItem = rightButton - presentationController.navigationItem.leftBarButtonItem = leftButton - presentationController.navigationItem.rightBarButtonItem = rightButton + configureSlides() + configureBackground() - configureSlides() - configureBackground() + window = UIWindow(frame: UIScreen.main.bounds) + window?.rootViewController = navigationController + window?.makeKeyAndVisible() - window = UIWindow(frame: UIScreen.main.bounds) - window?.rootViewController = navigationController - window?.makeKeyAndVisible() - - return true + return true } - func configureSlides() { + private func configureSlides() { let ratio: CGFloat = UIDevice.current.userInterfaceIdiom == .pad ? 1 : 0.4 let font = UIFont(name: "ArialRoundedMTBold", size: 42.0 * ratio)! let color = UIColor.white @@ -109,9 +109,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { presentationController.add(slides) } - func configureBackground() { + private func configureBackground() { let images = ["Cloud1", "Cloud2", "Cloud1"].map { UIImageView(image: UIImage(named: $0)) } - let content1 = Content(view: images[0], position: Position(left: -0.3, top: 0.2)) let content2 = Content(view: images[1], position: Position(right: -0.3, top: 0.22)) let content3 = Content(view: images[2], position: Position(left: 0.5, top: 0.5)) @@ -145,4 +144,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ], forPage: 4) } } - From 57933eb163aef638eb1e84bd7c8cc87987ede33b Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Mon, 2 Oct 2017 23:01:34 +0200 Subject: [PATCH 5/7] Update podspec --- Presentation.podspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Presentation.podspec b/Presentation.podspec index 410975c..294d699 100644 --- a/Presentation.podspec +++ b/Presentation.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Presentation" s.summary = "Presentation helps you to make tutorials, release notes and animated pages." - s.version = "3.1.0" + s.version = "4.0.0" s.homepage = "https://github.com/hyperoslo/Presentation" s.license = 'MIT' s.author = { "Hyper" => "ios@hyper.no" } @@ -12,6 +12,6 @@ Pod::Spec.new do |s| s.requires_arc = true s.source_files = 'Source/**/*' - s.dependency 'Pages' - s.dependency 'Cartography' + s.dependency 'Pages', '~> 2.0' + s.dependency 'Cartography', '~> 2.0' end From f0170fd2d2f45366b876fd74d5a04bcad9e161a5 Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Mon, 2 Oct 2017 23:06:02 +0200 Subject: [PATCH 6/7] Update travis config --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9cfc8a5..d4218ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ -osx_image: xcode8 +osx_image: xcode9 language: objective-c +xcode_sdk: iphonesimulator10.0 before_install: - brew update @@ -7,4 +8,5 @@ before_install: - travis_wait 35 carthage bootstrap --platform iOS script: -- xcodebuild clean build -project Presentation.xcodeproj -scheme "Presentation-iOS" -sdk iphonesimulator +- set -o pipefail +- travis_retry xcodebuild -project Presentation.xcodeproj -scheme "Presentation-iOS" -destination "platform=iOS Simulator,name=iPhone 6" build-for-testing test | xcpretty From 37521ed5cadddc7ea2fb916946deae0c9d0669ed Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Mon, 2 Oct 2017 23:34:25 +0200 Subject: [PATCH 7/7] Update travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d4218ed..6170d5c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,4 @@ before_install: script: - set -o pipefail -- travis_retry xcodebuild -project Presentation.xcodeproj -scheme "Presentation-iOS" -destination "platform=iOS Simulator,name=iPhone 6" build-for-testing test | xcpretty +- travis_retry xcodebuild clean build -project Presentation.xcodeproj -scheme "Presentation-iOS" -destination "platform=iOS Simulator,name=iPhone 6" | xcpretty