Skip to content

Commit

Permalink
support swift2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
marty-suzuki committed Sep 20, 2016
1 parent 9744225 commit e90f170
Show file tree
Hide file tree
Showing 45 changed files with 843 additions and 1,218 deletions.
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.3
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ SAHistoryNavigationViewController realizes iOS task manager like UI in UINavigat
- [x] Launch Navigation History with Long tap action of Back Bar Button
- [x] Support Swift2.0
- [x] Support 3D Touch (If device is not supported 3D Touch, automatically replacing to long tap gesture.)
- [x] Support Swift2.3

## Installation

Expand Down Expand Up @@ -106,7 +107,7 @@ This is delegate methods.

## Requirements

- Xcode 7.0 or greater
- Xcode 8.0 or greater
- iOS8.0 or greater
- [MisterFusion](https://github.com/szk-atmosphere/MisterFusion)

Expand Down
10 changes: 5 additions & 5 deletions SAHistoryNavigationViewController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

Pod::Spec.new do |s|
s.name = "SAHistoryNavigationViewController"
s.version = "2.3.0"
s.version = "2.4.0"
s.summary = "SAHistoryNavigationViewController realizes iOS task manager like UI in UINavigationContoller."

s.homepage = "https://github.com/szk-atmosphere/SAHistoryNavigationViewController"
s.homepage = "https://github.com/marty-suzuki/SAHistoryNavigationViewController"
s.license = 'MIT'
s.author = { "Taiki Suzuki" => "[email protected]" }
s.source = { :git => "https://github.com/szk-atmosphere/SAHistoryNavigationViewController.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/SzkAtmosphere'
s.source = { :git => "https://github.com/marty-suzuki/SAHistoryNavigationViewController.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/marty_suzuki'

s.platform = :ios, '8.0'
s.requires_arc = true
Expand All @@ -28,5 +28,5 @@ Pod::Spec.new do |s|

# s.public_header_files = 'Pod/Classes/**/*.h'
s.frameworks = 'UIKit', 'AudioToolbox'
s.dependency 'MisterFusion'
s.dependency 'MisterFusion', '~> 1.4.0'
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import UIKit

class SAHistoryNavigationTransitionController: NSObject, UIViewControllerAnimatedTransitioning {
//MARK: - Static constants
private static let kDefaultDuration: NSTimeInterval = 0.3

private struct Const {
static let defaultDuration: NSTimeInterval = 0.3
}

//MARK: - Properties
private(set) var navigationControllerOperation: UINavigationControllerOperation
private var currentTransitionContext: UIViewControllerContextTransitioning?
Expand All @@ -26,18 +28,16 @@ class SAHistoryNavigationTransitionController: NSObject, UIViewControllerAnimate

//MARK: Life cycle
func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
return SAHistoryNavigationTransitionController.kDefaultDuration
return Const.defaultDuration
}

func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
guard let
containerView = transitionContext.containerView(),
fromView = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)?.view,
toView = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)?.view
else {
return
}
guard
let fromView = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)?.view,
let toView = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)?.view
else { return }

let containerView = transitionContext.containerView()
currentTransitionContext = transitionContext
switch navigationControllerOperation {
case .Push:
Expand All @@ -49,42 +49,34 @@ class SAHistoryNavigationTransitionController: NSObject, UIViewControllerAnimate
transitionContext.completeTransition(!cancelled)
}
}
}

extension SAHistoryNavigationTransitionController {
func forceFinish() {
let navigationControllerOperation = self.navigationControllerOperation
if let backgroundView = backgroundView, alphaView = alphaView {
let dispatchTime = dispatch_time(DISPATCH_TIME_NOW, Int64((SAHistoryNavigationTransitionController.kDefaultDuration + 0.1) * Double(NSEC_PER_SEC)))
dispatch_after(dispatchTime, dispatch_get_main_queue()) { [weak self] in
if let currentTransitionContext = self?.currentTransitionContext {
let toViewContoller = currentTransitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)
let fromViewContoller = currentTransitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)

if let fromView = fromViewContoller?.view, toView = toViewContoller?.view {
switch navigationControllerOperation {
case .Push:
self?.pushAniamtionCompletion(currentTransitionContext, toView: toView, fromView: fromView, backgroundView: backgroundView, alphaView: alphaView)
case .Pop:
self?.popAniamtionCompletion(currentTransitionContext, toView: toView, fromView: fromView, backgroundView: backgroundView, alphaView: alphaView)
case .None:
let cancelled = currentTransitionContext.transitionWasCancelled()
currentTransitionContext.completeTransition(!cancelled)
}
self?.currentTransitionContext = nil
self?.backgroundView = nil
self?.alphaView = nil
}
}
guard let backgroundView = backgroundView, let alphaView = alphaView else { return }
let dispatchTime = dispatch_time(DISPATCH_TIME_NOW, Int64((Const.defaultDuration + 0.1) * Double(NSEC_PER_SEC)))
dispatch_after(dispatchTime, dispatch_get_main_queue()) { [weak self] in
guard let currentTransitionContext = self?.currentTransitionContext else { return }
let toViewContoller = currentTransitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)
let fromViewContoller = currentTransitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)

guard let fromView = fromViewContoller?.view, let toView = toViewContoller?.view else { return }
switch navigationControllerOperation {
case .Push:
self?.pushAniamtionCompletion(currentTransitionContext, toView: toView, fromView: fromView, backgroundView: backgroundView, alphaView: alphaView)
case .Pop:
self?.popAniamtionCompletion(currentTransitionContext, toView: toView, fromView: fromView, backgroundView: backgroundView, alphaView: alphaView)
case .None:
let cancelled = currentTransitionContext.transitionWasCancelled()
currentTransitionContext.completeTransition(!cancelled)
}
self?.currentTransitionContext = nil
self?.backgroundView = nil
self?.alphaView = nil
}
}
}

//MARK: - Pop animations
extension SAHistoryNavigationTransitionController {
//MARK: - Pop animations
private func popAnimation(transitionContext: UIViewControllerContextTransitioning, toView: UIView, fromView: UIView, containerView: UIView) {

let backgroundView = UIView(frame: containerView.bounds)
backgroundView.backgroundColor = .blackColor()
containerView.addSubview(backgroundView)
Expand Down Expand Up @@ -135,12 +127,9 @@ extension SAHistoryNavigationTransitionController {
self.backgroundView = nil
self.alphaView = nil
}
}

//MARK: - pushAnimations
extension SAHistoryNavigationTransitionController {
//MARK: - pushAnimations
private func pushAnimation(transitionContext: UIViewControllerContextTransitioning, toView: UIView, fromView: UIView, containerView: UIView) {

let backgroundView = UIView(frame: containerView.bounds)
backgroundView.backgroundColor = .blackColor()
containerView.addSubview(backgroundView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import UIKit

public class SAHistoryNavigationViewController: UINavigationController {
//MARK: - Static constants
private static let ImageScale: CGFloat = 1.0

private struct Const {
static let imageScale: CGFloat = 1.0
}

//MARK: - Properties
public var thirdDimensionalTouchThreshold: CGFloat = 0.5

Expand Down Expand Up @@ -73,7 +75,7 @@ public class SAHistoryNavigationViewController: UINavigationController {
}

override public func pushViewController(viewController: UIViewController, animated: Bool) {
if let image = visibleViewController?.screenshotFromWindow(self.dynamicType.ImageScale) {
if let image = visibleViewController?.screenshotFromWindow(Const.imageScale) {
screenshots += [image]
}
super.pushViewController(viewController, animated: animated)
Expand All @@ -95,22 +97,17 @@ public class SAHistoryNavigationViewController: UINavigationController {
public override func setViewControllers(viewControllers: [UIViewController], animated: Bool) {
super.setViewControllers(viewControllers, animated: animated)
for (currentIndex, viewController) in viewControllers.enumerate() {
if currentIndex == viewControllers.endIndex {
break
}
if let image = viewController.screenshotFromWindow(self.dynamicType.ImageScale) {
screenshots += [image]
}
if currentIndex == viewControllers.endIndex { break }
guard let image = viewController.screenshotFromWindow(Const.imageScale) else { continue }
screenshots += [image]
}
}

@available(iOS 9, *)
func handleThirdDimensionalTouch(gesture: SAThirdDimensionalTouchRecognizer) {
switch gesture.state {
case .Began:
guard let image = visibleViewController?.screenshotFromWindow(self.dynamicType.ImageScale) else {
return
}
guard let image = visibleViewController?.screenshotFromWindow(Const.imageScale) else { return }
screenshots += [image]

let historyViewController = createHistoryViewController()
Expand All @@ -124,9 +121,7 @@ public class SAHistoryNavigationViewController: UINavigationController {
screenshots.removeLast()
if gesture.percentage >= gesture.threshold {
interactiveTransition?.finishInteractiveTransition()
guard let visibleViewController = self.visibleViewController else {
return
}
guard let visibleViewController = self.visibleViewController else { return }
historyDelegate?.historyControllerDidShowHistory?(self, viewController: visibleViewController)
} else {
interactiveTransition?.cancelInteractiveTransition()
Expand Down Expand Up @@ -156,17 +151,13 @@ public class SAHistoryNavigationViewController: UINavigationController {

extension SAHistoryNavigationViewController {
override public func showHistory() {
guard let image = visibleViewController?.screenshotFromWindow(self.dynamicType.ImageScale) else {
return
}
guard let image = visibleViewController?.screenshotFromWindow(Const.imageScale) else { return }
screenshots += [image]
let historyViewController = createHistoryViewController()
self.historyViewController = historyViewController
setNavigationBarHidden(true, animated: false)
presentViewController(historyViewController, animated: true) {
guard let visibleViewController = self.visibleViewController else {
return
}
guard let visibleViewController = self.visibleViewController else { return }
self.historyDelegate?.historyControllerDidShowHistory?(self, viewController: visibleViewController)
}
}
Expand All @@ -183,9 +174,7 @@ extension SAHistoryNavigationViewController {
//MARK: - UINavigationBarDelegate
extension SAHistoryNavigationViewController: UINavigationBarDelegate {
public func navigationBar(navigationBar: UINavigationBar, didPopItem item: UINavigationItem) {
guard let items = navigationBar.items else {
return
}
guard let items = navigationBar.items else { return }
screenshots.removeRange(items.count..<screenshots.count)
}
}
Expand All @@ -208,10 +197,7 @@ extension SAHistoryNavigationViewController : UIViewControllerTransitioningDeleg
//MARK: - SAHistoryViewControllerDelegate
extension SAHistoryNavigationViewController: SAHistoryViewControllerDelegate {
func historyViewController(viewController: SAHistoryViewController, didSelectIndex index: Int) {
if viewControllers.count - 1 < index {
return
}

if viewControllers.count - 1 < index { return }
viewController.dismissViewControllerAnimated(true) { _ in
self.popToViewController(self.viewControllers[index], animated: false)
self.historyViewController = nil
Expand All @@ -231,13 +217,9 @@ extension SAHistoryNavigationViewController: UIGestureRecognizerDelegate {
return true
}
}

if let gestureRecognizer = gestureRecognizer as? UIScreenEdgePanGestureRecognizer {
if view == gestureRecognizer.view {
return true
}
if let gestureRecognizer = gestureRecognizer as? UIScreenEdgePanGestureRecognizer where view == gestureRecognizer.view {
return true
}

return false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import UIKit

class SAHistoryViewAnimatedTransitioning: NSObject, UIViewControllerAnimatedTransitioning {
//MARK: - Static Constants
static private let Duration: NSTimeInterval = 0.25
static private let Scale: CGFloat = 0.7
private struct Const {
static let duration: NSTimeInterval = 0.25
static let scale: CGFloat = 0.7
}

//MARK: - Properties
private var isPresenting = true
Expand All @@ -24,44 +26,35 @@ class SAHistoryViewAnimatedTransitioning: NSObject, UIViewControllerAnimatedTran

//MARK - Life cycle
func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
return SAHistoryViewAnimatedTransitioning.Duration
return Const.duration
}

func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
guard let containerView = transitionContext.containerView() else {
return
}

guard let toVC = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey) else {
return
}

guard let fromVC = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey) else {
return
}

guard
let toVC = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey),
let fromVC = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)
else { return }
let containerView = transitionContext.containerView()
if isPresenting {
pushAniamtion(transitionContext, containerView: containerView, toVC: toVC, fromVC: fromVC)
} else {
popAniamtion(transitionContext, containerView: containerView, toVC: toVC, fromVC: fromVC)
return
}
popAniamtion(transitionContext, containerView: containerView, toVC: toVC, fromVC: fromVC)
}
}

//MARK: - Animations
extension SAHistoryViewAnimatedTransitioning {
private func pushAniamtion(transitionContext: UIViewControllerContextTransitioning, containerView: UIView, toVC: UIViewController, fromVC: UIViewController) {
guard let hvc = toVC as? SAHistoryViewController else {
return
}
guard let hvc = toVC as? SAHistoryViewController else { return }

containerView.addSubview(toVC.view)
fromVC.view.hidden = true
hvc.view.frame = containerView.bounds
hvc.collectionView.transform = CGAffineTransformIdentity

UIView.animateWithDuration(transitionDuration(transitionContext), delay: 0, options: .CurveEaseOut, animations: {
hvc.collectionView.transform = CGAffineTransformMakeScale(SAHistoryViewAnimatedTransitioning.Scale, SAHistoryViewAnimatedTransitioning.Scale)
hvc.collectionView.transform = CGAffineTransformMakeScale(Const.scale, Const.scale)
}) { finished in
let cancelled = transitionContext.transitionWasCancelled()
if cancelled {
Expand All @@ -77,14 +70,12 @@ extension SAHistoryViewAnimatedTransitioning {
}

private func popAniamtion(transitionContext: UIViewControllerContextTransitioning, containerView: UIView, toVC: UIViewController, fromVC: UIViewController) {
guard let hvc = fromVC as? SAHistoryViewController else {
return
}
guard let hvc = fromVC as? SAHistoryViewController else { return }

containerView.addSubview(toVC.view)
toVC.view.hidden = true
hvc.view.frame = containerView.bounds
hvc.collectionView.transform = CGAffineTransformMakeScale(SAHistoryViewAnimatedTransitioning.Scale, SAHistoryViewAnimatedTransitioning.Scale)
hvc.collectionView.transform = CGAffineTransformMakeScale(Const.scale, Const.scale)

UIView.animateWithDuration(transitionDuration(transitionContext), delay: 0, options: .CurveEaseOut, animations: {
hvc.collectionView.transform = CGAffineTransformIdentity
Expand Down
Loading

0 comments on commit e90f170

Please sign in to comment.