Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scroll view slide back #78

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions FDFullscreenPopGesture.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@


Pod::Spec.new do |s|
s.name = "FDFullscreenPopGesture"
s.version = "1.1"
s.version = "1.1.1"
s.summary = "An UINavigationController's category to enable fullscreen pop gesture in iOS7+ system style with an AOP useage."
s.description = "An UINavigationController's category to enable fullscreen pop gesture in iOS7+ system style with an AOP useage. Just pod in 2 files and no need for any setups."
s.homepage = "https://github.com/forkingdog/FDFullscreenPopGesture"
Expand All @@ -13,9 +14,9 @@ Pod::Spec.new do |s|
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.platform = :ios, "7.0"
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.source = { :git => "https://github.com/forkingdog/FDFullscreenPopGesture.git", :tag => "1.1" }
s.source = { :git => "https://github.com/forkingdog/FDFullscreenPopGesture.git", :tag => "1.1.1" }
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.source_files = "FDFullscreenPopGesture/*.{h,m}"
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.requires_arc = true
end
end
121 changes: 115 additions & 6 deletions FDFullscreenPopGesture/UINavigationController+FDFullscreenPopGesture.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,61 @@
// SOFTWARE.

#import "UINavigationController+FDFullscreenPopGesture.h"
#import <UIKit/UIGestureRecognizerSubclass.h>
#import <objc/runtime.h>

@interface FDPanGestureRecognizer : UIPanGestureRecognizer

@property (nonatomic, strong, readonly) UIEvent *event;

- (CGPoint)beganLocationInView:(UIView *)view;

@end

@interface FDPanGestureRecognizer ()

@property (strong, nonatomic) UIEvent *event;
@property (assign, nonatomic) CGPoint beganLocation;
@property (assign, nonatomic) NSTimeInterval beganTime;

@end

@implementation FDPanGestureRecognizer

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
self.event = event;
self.beganTime = event.timestamp;
self.beganLocation = [touch locationInView:self.view];
[super touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if (self.state == UIGestureRecognizerStatePossible && event.timestamp - self.beganTime > 0.3) {
self.state = UIGestureRecognizerStateFailed;
return;
}
[super touchesMoved:touches withEvent:event];
}

- (void)reset
{
self.event = nil;
self.beganTime = 0;
self.beganLocation = CGPointZero;
[super reset];
}

- (CGPoint)beganLocationInView:(UIView *)view
{
return [view convertPoint:self.beganLocation fromView:self.view];
}

@end


@interface _FDFullscreenPopGestureRecognizerDelegate : NSObject <UIGestureRecognizerDelegate>

@property (nonatomic, weak) UINavigationController *navigationController;
Expand Down Expand Up @@ -50,7 +103,7 @@ - (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer
if (maxAllowedInitialDistance > 0 && beginningLocation.x > maxAllowedInitialDistance) {
return NO;
}

// Ignore pan gesture when the navigation controller is currently in transition.
if ([[self.navigationController valueForKey:@"_isTransitioning"] boolValue]) {
return NO;
Expand All @@ -65,6 +118,62 @@ - (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer
return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{

// Ignore when no view controller is pushed into the navigation stack.
if (self.navigationController.viewControllers.count <= 1) {
return NO;
}

// Ignore when the active view controller doesn't allow interactive pop.
UIViewController *topViewController = self.navigationController.viewControllers.lastObject;
if (topViewController.fd_interactivePopDisabled) {
return NO;
}

// Ignore when the beginning location is beyond max allowed initial distance to left edge.
CGPoint beginningLocation = [gestureRecognizer locationInView:gestureRecognizer.view];
CGFloat maxAllowedInitialDistance = topViewController.fd_interactivePopMaxAllowedInitialDistanceToLeftEdge;
if (maxAllowedInitialDistance > 0 && beginningLocation.x > maxAllowedInitialDistance) {
return NO;
}

// Ignore pan gesture when the navigation controller is currently in transition.
if ([[self.navigationController valueForKey:@"_isTransitioning"] boolValue]) {
return NO;
}

FDPanGestureRecognizer* fd_gestureRecognizer = (FDPanGestureRecognizer *)gestureRecognizer;
// Prevent calling the handler when the gesture begins in an opposite direction.
CGPoint translation = [fd_gestureRecognizer translationInView:fd_gestureRecognizer.view];
if (translation.x <= 0) {
return NO;
}

CGPoint touchPoint = [fd_gestureRecognizer beganLocationInView:fd_gestureRecognizer.view];
// If within thirty hit area on the left, forced back
if (touchPoint.x < 30) {
NSSet *touchs = [fd_gestureRecognizer.event touchesForGestureRecognizer:otherGestureRecognizer];
[otherGestureRecognizer touchesCancelled:touchs withEvent:fd_gestureRecognizer.event];
return YES;
}

// If there are multiple gestures
// And other gestures of view is a scroll view
// If you scroll view scroll to less than zero, the scroll view gesture cancellation effect
if ([[otherGestureRecognizer view] isKindOfClass:[UIScrollView class]]) {
UIScrollView *scrollView = (UIScrollView *)[otherGestureRecognizer view];
if (scrollView.contentOffset.x <= 0) {
NSSet *touchs = [fd_gestureRecognizer.event touchesForGestureRecognizer:otherGestureRecognizer];
[otherGestureRecognizer touchesCancelled:touchs withEvent:fd_gestureRecognizer.event];
return YES;
}
}

return NO;
}

@end

typedef void (^_FDViewControllerWillAppearInjectBlock)(UIViewController *viewController, BOOL animated);
Expand Down Expand Up @@ -150,14 +259,14 @@ - (void)fd_pushViewController:(UIViewController *)viewController animated:(BOOL)

// Add our own gesture recognizer to where the onboard screen edge pan gesture recognizer is attached to.
[self.interactivePopGestureRecognizer.view addGestureRecognizer:self.fd_fullscreenPopGestureRecognizer];

// Forward the gesture events to the private handler of the onboard gesture recognizer.
NSArray *internalTargets = [self.interactivePopGestureRecognizer valueForKey:@"targets"];
id internalTarget = [internalTargets.firstObject valueForKey:@"target"];
SEL internalAction = NSSelectorFromString(@"handleNavigationTransition:");
self.fd_fullscreenPopGestureRecognizer.delegate = self.fd_popGestureRecognizerDelegate;
[self.fd_fullscreenPopGestureRecognizer addTarget:internalTarget action:internalAction];

// Disable the onboard gesture recognizer.
self.interactivePopGestureRecognizer.enabled = NO;
}
Expand Down Expand Up @@ -198,7 +307,7 @@ - (void)fd_setupViewControllerBasedNavigationBarAppearanceIfNeeded:(UIViewContro
- (_FDFullscreenPopGestureRecognizerDelegate *)fd_popGestureRecognizerDelegate
{
_FDFullscreenPopGestureRecognizerDelegate *delegate = objc_getAssociatedObject(self, _cmd);

if (!delegate) {
delegate = [[_FDFullscreenPopGestureRecognizerDelegate alloc] init];
delegate.navigationController = self;
Expand All @@ -211,9 +320,9 @@ - (_FDFullscreenPopGestureRecognizerDelegate *)fd_popGestureRecognizerDelegate
- (UIPanGestureRecognizer *)fd_fullscreenPopGestureRecognizer
{
UIPanGestureRecognizer *panGestureRecognizer = objc_getAssociatedObject(self, _cmd);

if (!panGestureRecognizer) {
panGestureRecognizer = [[UIPanGestureRecognizer alloc] init];
panGestureRecognizer = [[FDPanGestureRecognizer alloc] init];
panGestureRecognizer.maximumNumberOfTouches = 1;

objc_setAssociatedObject(self, _cmd, panGestureRecognizer, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
3855B3261CCF6EED0072D889 /* FDTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3855B3251CCF6EED0072D889 /* FDTableViewController.m */; };
4894F4201B183DE3009F44D9 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4894F41F1B183DE3009F44D9 /* main.m */; };
4894F4231B183DE3009F44D9 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4894F4221B183DE3009F44D9 /* AppDelegate.m */; };
4894F4291B183DE3009F44D9 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4894F4271B183DE3009F44D9 /* Main.storyboard */; };
Expand All @@ -16,6 +17,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
3855B3241CCF6EED0072D889 /* FDTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FDTableViewController.h; sourceTree = "<group>"; };
3855B3251CCF6EED0072D889 /* FDTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FDTableViewController.m; sourceTree = "<group>"; };
4894F41A1B183DE3009F44D9 /* FDFullscreenPopGestureDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FDFullscreenPopGestureDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
4894F41E1B183DE3009F44D9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4894F41F1B183DE3009F44D9 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -61,6 +64,8 @@
4894F4431B183DEF009F44D9 /* FDFullscreenPopGesture */,
4894F4211B183DE3009F44D9 /* AppDelegate.h */,
4894F4221B183DE3009F44D9 /* AppDelegate.m */,
3855B3241CCF6EED0072D889 /* FDTableViewController.h */,
3855B3251CCF6EED0072D889 /* FDTableViewController.m */,
4894F4271B183DE3009F44D9 /* Main.storyboard */,
4894F42A1B183DE3009F44D9 /* Images.xcassets */,
4894F42C1B183DE3009F44D9 /* LaunchScreen.xib */,
Expand Down Expand Up @@ -161,6 +166,7 @@
4894F4231B183DE3009F44D9 /* AppDelegate.m in Sources */,
4894F4461B183E99009F44D9 /* UINavigationController+FDFullscreenPopGesture.m in Sources */,
4894F4201B183DE3009F44D9 /* main.m in Sources */,
3855B3261CCF6EED0072D889 /* FDTableViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -305,6 +311,7 @@
4894F43F1B183DE3009F44D9 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<objects>
Expand All @@ -14,13 +15,13 @@
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015年 forkingdog. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="FDFullscreenPopGestureDemo" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
<rect key="frame" x="20" y="140" width="441" height="43"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
Expand Down
Loading