remove self.
This commit is contained in:
parent
9aad8e897c
commit
15d60bd3eb
@ -45,11 +45,11 @@ fileprivate enum SubNavPanningDirection : Int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public init(viewController: UIViewController, delegate: SubNavSwipeNavigationProtocol) {
|
public init(viewController: UIViewController, delegate: SubNavSwipeNavigationProtocol) {
|
||||||
self.pannablePercentage = 0.15
|
pannablePercentage = 0.15
|
||||||
self.delegate = delegate
|
self.delegate = delegate
|
||||||
super.init()
|
super.init()
|
||||||
self.panGesture = UIPanGestureRecognizer.init(target: self, action: #selector(handlePanGesture));
|
panGesture = UIPanGestureRecognizer.init(target: self, action: #selector(handlePanGesture));
|
||||||
viewController.view.addGestureRecognizer(self.panGesture)
|
viewController.view.addGestureRecognizer(panGesture)
|
||||||
}
|
}
|
||||||
|
|
||||||
//overrides
|
//overrides
|
||||||
@ -91,20 +91,20 @@ fileprivate enum SubNavPanningDirection : Int {
|
|||||||
|
|
||||||
case .began:
|
case .began:
|
||||||
// Begin the transition to the next page.
|
// Begin the transition to the next page.
|
||||||
self.panning = true
|
panning = true
|
||||||
if velocityX < 0 && pannableFrameRight.contains(locationInView) {
|
if velocityX < 0 && pannableFrameRight.contains(locationInView) {
|
||||||
self.delegate?.swipeLeft()
|
delegate?.swipeLeft()
|
||||||
self.panningDirection = .left
|
panningDirection = .left
|
||||||
} else if velocityX > 0 && pannableFrameLeft.contains(locationInView){
|
} else if velocityX > 0 && pannableFrameLeft.contains(locationInView){
|
||||||
self.delegate?.swipeRight()
|
delegate?.swipeRight()
|
||||||
self.panningDirection = .right
|
panningDirection = .right
|
||||||
}
|
}
|
||||||
|
|
||||||
case .changed:
|
case .changed:
|
||||||
guard self.interactive else { return }
|
guard interactive else { return }
|
||||||
|
|
||||||
if self.panningDirection == .right && translation.x < 0 ||
|
if panningDirection == .right && translation.x < 0 ||
|
||||||
self.panningDirection == .left && translation.x > 0 {
|
panningDirection == .left && translation.x > 0 {
|
||||||
percentage = 0
|
percentage = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,27 +114,27 @@ fileprivate enum SubNavPanningDirection : Int {
|
|||||||
if percentage > 1.00 {
|
if percentage > 1.00 {
|
||||||
percentage = 1.00;
|
percentage = 1.00;
|
||||||
}
|
}
|
||||||
self.shouldCompleteTransition = percentage > 0.65;
|
shouldCompleteTransition = percentage > 0.65;
|
||||||
self.update(percentage)
|
update(percentage)
|
||||||
self.delegate?.update(percentage: percentage)
|
delegate?.update(percentage: percentage)
|
||||||
|
|
||||||
case .cancelled:
|
case .cancelled:
|
||||||
self.cancel()
|
cancel()
|
||||||
|
|
||||||
case .ended:
|
case .ended:
|
||||||
if ((percentage < 0) != (velocityX < 0)) && abs(velocityX) > 50 {
|
if ((percentage < 0) != (velocityX < 0)) && abs(velocityX) > 50 {
|
||||||
// If we are moving back toward the previous view we want to cancel. (the speed threshold is for shaky hands)
|
// If we are moving back toward the previous view we want to cancel. (the speed threshold is for shaky hands)
|
||||||
self.cancel()
|
cancel()
|
||||||
} else if abs(velocityX) > 300.0 || shouldCompleteTransition {
|
} else if abs(velocityX) > 300.0 || shouldCompleteTransition {
|
||||||
// Need to cancel the transition if we pass the threshold, but from a opposite direction(e.g. Start panning from left edge to right, then move back, pass the start x location, end with a high velocityX)
|
// Need to cancel the transition if we pass the threshold, but from a opposite direction(e.g. Start panning from left edge to right, then move back, pass the start x location, end with a high velocityX)
|
||||||
if ((panningDirection == .right) && translation.x < 0) || ((panningDirection == .left) && translation.x > 0) {
|
if ((panningDirection == .right) && translation.x < 0) || ((panningDirection == .left) && translation.x > 0) {
|
||||||
self.cancel()
|
cancel()
|
||||||
} else {
|
} else {
|
||||||
// If we pass the speed or screen percentage thresholds, move on to the next screen.
|
// If we pass the speed or screen percentage thresholds, move on to the next screen.
|
||||||
self.finish()
|
finish()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.cancel()
|
cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -23,25 +23,25 @@ import MVMCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
public func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
||||||
self.animationTime = 0.5
|
animationTime = 0.5
|
||||||
return self.animationTime
|
return animationTime
|
||||||
}
|
}
|
||||||
|
|
||||||
public func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
public func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||||
self.controller?.view.isUserInteractionEnabled = false
|
controller?.view.isUserInteractionEnabled = false
|
||||||
let containerView = transitionContext.containerView
|
let containerView = transitionContext.containerView
|
||||||
|
|
||||||
guard let originalViewController = transitionContext.viewController(forKey: .from),
|
guard let originalViewController = transitionContext.viewController(forKey: .from),
|
||||||
let destinationViewController = transitionContext.viewController(forKey: .to) else { return }
|
let destinationViewController = transitionContext.viewController(forKey: .to) else { return }
|
||||||
|
|
||||||
var destStartFrame = containerView.bounds
|
var destStartFrame = containerView.bounds
|
||||||
destStartFrame.origin.x = self.direction == .right ? -destStartFrame.size.width : destStartFrame.size.width
|
destStartFrame.origin.x = direction == .right ? -destStartFrame.size.width : destStartFrame.size.width
|
||||||
containerView.addSubview(destinationViewController.view)
|
containerView.addSubview(destinationViewController.view)
|
||||||
destinationViewController.view.frame = destStartFrame
|
destinationViewController.view.frame = destStartFrame
|
||||||
|
|
||||||
let destEndFrame = containerView.bounds
|
let destEndFrame = containerView.bounds
|
||||||
var origEndFrame = containerView.bounds
|
var origEndFrame = containerView.bounds
|
||||||
origEndFrame.origin.x = self.direction == .right ? origEndFrame.size.width : -origEndFrame.size.width
|
origEndFrame.origin.x = direction == .right ? origEndFrame.size.width : -origEndFrame.size.width
|
||||||
|
|
||||||
UIView.animate(withDuration: animationTime, animations: {
|
UIView.animate(withDuration: animationTime, animations: {
|
||||||
originalViewController.view.frame = origEndFrame
|
originalViewController.view.frame = origEndFrame
|
||||||
@ -53,8 +53,8 @@ import MVMCore
|
|||||||
|
|
||||||
public func animationEnded(_ transitionCompleted: Bool) {
|
public func animationEnded(_ transitionCompleted: Bool) {
|
||||||
if !transitionCompleted {
|
if !transitionCompleted {
|
||||||
self.interactiveTransitionCanceled = true
|
interactiveTransitionCanceled = true
|
||||||
}
|
}
|
||||||
self.controller?.view.isUserInteractionEnabled = true
|
controller?.view.isUserInteractionEnabled = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user