Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxAIRINxxx committed Sep 17, 2015
1 parent cc1e5e8 commit f1b6355
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions ARNTransitionAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,7 @@ public class ARNTransitionAnimator: UIPercentDrivenInteractiveTransition {
}
public var panCompletionThreshold : CGFloat = 100.0
public var direction : ARNTransitionAnimatorDirection = .Bottom
public var contentScrollView : UIScrollView? {
didSet {
if let _contentScrollView = self.contentScrollView {
self.tmpBounces = _contentScrollView.bounces
}
}
}
public var contentScrollView : UIScrollView?
public var interactiveType : ARNTransitionAnimatorOperation = .None {
didSet {
if self.interactiveType == .None {
Expand Down Expand Up @@ -80,12 +74,11 @@ public class ARNTransitionAnimator: UIPercentDrivenInteractiveTransition {

private(set) var operationType : ARNTransitionAnimatorOperation
private(set) var isPresenting : Bool = true
private(set) var isTransitioning : Bool = false
private(set) var isTransitioning : Bool = false

private var gesture : UIPanGestureRecognizer?
private var transitionContext : UIViewControllerContextTransitioning?
private var panLocationStart : CGFloat = 0.0
private var tmpBounces: Bool = true

deinit {
self.unregisterPanGesture()
Expand Down Expand Up @@ -253,7 +246,6 @@ public class ARNTransitionAnimator: UIPercentDrivenInteractiveTransition {
if let _contentScrollView = self.contentScrollView {
if self.isTransitioning == false && _contentScrollView.contentOffset.y <= 0 {
self.startGestureTransition()
self.contentScrollView!.bounces = false
} else {
self.updateInteractiveTransition(animationRatio)
}
Expand All @@ -270,16 +262,19 @@ public class ARNTransitionAnimator: UIPercentDrivenInteractiveTransition {
}

if velocityForSelectedDirection > self.panCompletionThreshold && (self.direction == .Right || self.direction == .Bottom) {
self.finishInteractiveTransition()
self.finishInteractiveTransitionAnimated(true)
} else if velocityForSelectedDirection < -self.panCompletionThreshold && (self.direction == .Left || self.direction == .Top) {
self.finishInteractiveTransition()
self.finishInteractiveTransitionAnimated(true)
} else {
self.cancelInteractiveTransition()
let animated = self.contentScrollView?.contentOffset.y <= 0
self.cancelInteractiveTransitionAnimated(animated)
}
self.resetGestureTransitionSetting()
} else {
self.resetGestureTransitionSetting()
self.cancelInteractiveTransition()
if self.isTransitioning {
self.cancelInteractiveTransitionAnimated(true)
}
}
}

Expand All @@ -303,9 +298,6 @@ public class ARNTransitionAnimator: UIPercentDrivenInteractiveTransition {

func resetGestureTransitionSetting() {
self.isTransitioning = false
if let _contentScrollView = self.contentScrollView {
_contentScrollView.bounces = self.tmpBounces
}
}
}

Expand Down Expand Up @@ -401,25 +393,25 @@ extension ARNTransitionAnimator {
}
}

public override func finishInteractiveTransition() {
public func finishInteractiveTransitionAnimated(animated: Bool) {
super.finishInteractiveTransition()
if let transitionContext = self.transitionContext {
let containerView = transitionContext.containerView()
self.animateWithDuration(
self.transitionDuration(transitionContext),
animated ? self.transitionDuration(transitionContext) : 0,
containerView: containerView!,
completeTransition: true) {
transitionContext.completeTransition(true)
}
}
}

public override func cancelInteractiveTransition() {
public func cancelInteractiveTransitionAnimated(animated: Bool) {
super.cancelInteractiveTransition()
if let transitionContext = self.transitionContext {
let containerView = transitionContext.containerView()
self.animateWithDuration(
self.transitionDuration(transitionContext),
animated ? self.transitionDuration(transitionContext) : 0,
containerView: containerView!,
completeTransition: false) {
transitionContext.completeTransition(false)
Expand Down

0 comments on commit f1b6355

Please sign in to comment.