Skip to content

Commit 5a0d464

Browse files
seedanteseedante
authored and
seedante
committed
Enable pop transition. Do not need you to add code for this.
1 parent 0d79199 commit 5a0d464

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

Classes/SDENavigationControllerDelegate.swift

+7-4
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,29 @@ import UIKit
1212
class SDENavigationControllerDelegate: NSObject, UINavigationControllerDelegate {
1313

1414
var interactive = false
15-
var isPush = false
1615
var animationController: UIViewControllerAnimatedTransitioning!
1716
var interactionController: UIPercentDrivenInteractiveTransition?
1817

1918
//MARK: UINavigationControllerDelegate
2019
func navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
2120

2221
animationController = SDEPushAndPopAnimationController(operation: operation)
23-
isPush = (operation == .Push)
22+
if operation == .Push{
23+
if let toCollectionVC = toVC as? UICollectionViewController{
24+
interactionController = SDEPopPinchInteractionController(toVC: toCollectionVC, holder: self)
25+
}
26+
}
27+
2428
return animationController
2529
}
2630

2731
func navigationController(navigationController: UINavigationController, interactionControllerForAnimationController animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
2832

33+
// interactive can only update in gesture action
2934
if interactive{
30-
interactionController = UIPercentDrivenInteractiveTransition()
3135
return interactionController
3236
}
3337

34-
interactionController = nil
3538
return nil
3639
}
3740

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//
2+
// SDEPushAndPopInteractionController.swift
3+
// SDECollectionViewAlbumTransition
4+
//
5+
// Created by seedante on 15/10/19.
6+
// Copyright © 2015年 seedante. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class SDEPopPinchInteractionController: UIPercentDrivenInteractiveTransition {
12+
var pinchGesture = UIPinchGestureRecognizer()
13+
var topVC: UICollectionViewController
14+
unowned var holder: SDENavigationControllerDelegate
15+
16+
init(toVC topVC: UICollectionViewController, holder: SDENavigationControllerDelegate) {
17+
self.topVC = topVC
18+
self.holder = holder
19+
super.init()
20+
addPinchGestureOnView(self.topVC.view)
21+
}
22+
23+
func addPinchGestureOnView(view: UIView){
24+
pinchGesture.addTarget(self, action: "sde_handlePinch:")
25+
view.addGestureRecognizer(pinchGesture)
26+
}
27+
28+
func sde_handlePinch(gesture: UIPinchGestureRecognizer){
29+
switch gesture.state{
30+
case .Began:
31+
if gesture.scale < 1.0{
32+
holder.interactive = true
33+
topVC.navigationController?.popViewControllerAnimated(true)
34+
}
35+
case .Changed:
36+
if gesture.scale < 1.0{
37+
let progress = 1.0 - gesture.scale
38+
self.updateInteractiveTransition(progress)
39+
}
40+
case .Ended:
41+
if gesture.scale < 1.0{
42+
let progress = 1.0 - gesture.scale
43+
if progress > 0.4{
44+
self.finishInteractiveTransition()
45+
}else{
46+
self.cancelInteractiveTransition()
47+
}
48+
holder.interactive = false
49+
}
50+
default:
51+
holder.interactive = false
52+
}
53+
}
54+
55+
deinit{
56+
print("deinit")
57+
pinchGesture.view?.removeGestureRecognizer(pinchGesture)
58+
}
59+
}

SDECollectionViewAlbumTransition.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
FD83B6221BD529C100C4326E /* SDEPopPinchInteractionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD83B6211BD529C100C4326E /* SDEPopPinchInteractionController.swift */; settings = {ASSET_TAGS = (); }; };
1011
FDB179B41BD00B610029A9AB /* UICollectionViewControllerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDB179B01BD00B610029A9AB /* UICollectionViewControllerExtension.swift */; settings = {ASSET_TAGS = (); }; };
1112
FDBB4B4F1B5BDFBE00B6D674 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDBB4B4E1B5BDFBE00B6D674 /* AppDelegate.swift */; };
1213
FDBB4B591B5BDFBE00B6D674 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FDBB4B571B5BDFBE00B6D674 /* LaunchScreen.storyboard */; };
@@ -24,6 +25,7 @@
2425
/* End PBXBuildFile section */
2526

2627
/* Begin PBXFileReference section */
28+
FD83B6211BD529C100C4326E /* SDEPopPinchInteractionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SDEPopPinchInteractionController.swift; path = Classes/SDEPopPinchInteractionController.swift; sourceTree = "<group>"; };
2729
FDB179B01BD00B610029A9AB /* UICollectionViewControllerExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UICollectionViewControllerExtension.swift; path = Classes/Extension/UICollectionViewControllerExtension.swift; sourceTree = "<group>"; };
2830
FDBB4B4B1B5BDFBE00B6D674 /* SDECollectionViewAlbumTransition.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SDECollectionViewAlbumTransition.app; sourceTree = BUILT_PRODUCTS_DIR; };
2931
FDBB4B4E1B5BDFBE00B6D674 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -93,6 +95,7 @@
9395
isa = PBXGroup;
9496
children = (
9597
FDBB4B621B5BE02400B6D674 /* SDEPushAndPopAnimationController.swift */,
98+
FD83B6211BD529C100C4326E /* SDEPopPinchInteractionController.swift */,
9699
FDE437501BCF86FC001A6BF8 /* SDENavigationControllerDelegate.swift */,
97100
FDE437551BCFB09B001A6BF8 /* Extension */,
98101
);
@@ -187,6 +190,7 @@
187190
FDBB4B6C1B5BE02400B6D674 /* SDEAdaptiveAssetCell.swift in Sources */,
188191
FDE437511BCF86FC001A6BF8 /* SDENavigationControllerDelegate.swift in Sources */,
189192
FDBB4B4F1B5BDFBE00B6D674 /* AppDelegate.swift in Sources */,
193+
FD83B6221BD529C100C4326E /* SDEPopPinchInteractionController.swift in Sources */,
190194
FDBB4B681B5BE02400B6D674 /* SDEAlbumViewController.swift in Sources */,
191195
FDB179B41BD00B610029A9AB /* UICollectionViewControllerExtension.swift in Sources */,
192196
);

0 commit comments

Comments
 (0)