Skip to content
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
13 changes: 0 additions & 13 deletions RxWebViewController/RxWebViewNavigationViewController.h

This file was deleted.

76 changes: 0 additions & 76 deletions RxWebViewController/RxWebViewNavigationViewController.m

This file was deleted.

59 changes: 59 additions & 0 deletions RxWebViewController/UINavigationController+RxWebViewNavigation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// UINavigationController+RxWebViewNavigation.m
// RxWebViewController
//
// Created by roxasora on 15/10/23.
// Copyright © 2015年 roxasora. All rights reserved.
//

#import "RxWebViewController.h"
#import <objc/runtime.h>

@implementation UINavigationController (RxWebViewNavigation)

+ (void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// UINavigationController 实现了协议方法 navigationBar:shouldPopItem:,因此为了省事就直接交换了
method_exchangeImplementations(class_getInstanceMethod(self, @selector(navigationBar:shouldPopItem:)),
class_getInstanceMethod(self, @selector(rx_navigationBar:shouldPopItem:)));
});
}

// 改进思路来自 [截获导航控制器系统返回按钮的点击pop及右滑pop事件](http://www.jianshu.com/p/6376149a2c4c)
- (BOOL)rx_navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item
{
UIViewController *topVC = self.topViewController;

// 通过代码 pop 时,顶层视图控制器出栈后,此方法才会被调用
// 也就是说,此时获取到的顶层视图控制器其实是原顶层视图控制器的上一层视图控制器
// 而参数 item 却依然是原顶层视图控制器的 navigationItem
// 因此,如果 navigationItem 不同,就说明此方法是因为通过代码 pop 而调用的,此时应该沿用默认实现
if (item != topVC.navigationItem) {
return [self rx_navigationBar:navigationBar shouldPopItem:item];
}

// 能来到这里说明此方法是由于点击返回按钮而调用的,此时顶层视图控制器尚未出栈
// 若顶层视图控制器是 RxWebViewController,并且网页可以返回,此时应该将网页返回,而不是 pop 顶层视图控制器
if ([topVC isKindOfClass:[RxWebViewController class]]) {
RxWebViewController *webVC = (RxWebViewController*)topVC;
if (webVC.webView.canGoBack) {
[webVC.webView goBack];
// 最后一个子视图即是返回按钮图片,由于 pop 操作,它会变淡
// 而此时希望取消 pop 操作,并不希望返回按钮图片变淡,因此重新恢复它的透明度
[[self.navigationBar subviews] lastObject].alpha = 1;
// 由于此时不希望 pop,因此返回 NO
return NO;
}
// 虽然顶层视图控制器是 RxWebViewController,但是网页不可返回上一页了
// 此时应该像普通情况一样 pop 顶层视图控制器,因此这里应该沿用默认实现
return [self rx_navigationBar:navigationBar shouldPopItem:item];
}

// 来到这里说明此方法是由于点击返回按钮而调用的,此时顶层视图控制器尚未出栈,但它不是 RxWebViewController
// 此时也应该像普通情况一样 pop 顶层视图控制器,因此这里同样应该沿用默认实现
return [self rx_navigationBar:navigationBar shouldPopItem:item];
}

@end
20 changes: 5 additions & 15 deletions RxWebViewControllerTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
objects = {

/* Begin PBXBuildFile section */
2DE53C3B1CCF04C2006B9162 /* UINavigationController+RxWebViewNavigation.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DE53C3A1CCF04C2006B9162 /* UINavigationController+RxWebViewNavigation.m */; };
F53D31EC1BDB339D002322E1 /* Reveal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F53D31EB1BDB339D002322E1 /* Reveal.framework */; };
F59CDE9F1C1FBFB9008B5358 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F59CDE801C1FBFB9008B5358 /* AppDelegate.m */; };
F59CDEA01C1FBFB9008B5358 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F59CDE811C1FBFB9008B5358 /* Assets.xcassets */; };
F59CDEA11C1FBFB9008B5358 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F59CDE821C1FBFB9008B5358 /* LaunchScreen.storyboard */; };
F59CDEA21C1FBFB9008B5358 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F59CDE841C1FBFB9008B5358 /* Main.storyboard */; };
F59CDEA31C1FBFB9008B5358 /* demo.gif in Resources */ = {isa = PBXBuildFile; fileRef = F59CDE861C1FBFB9008B5358 /* demo.gif */; };
F59CDEA41C1FBFB9008B5358 /* icon-140.png in Resources */ = {isa = PBXBuildFile; fileRef = F59CDE871C1FBFB9008B5358 /* icon-140.png */; };
F59CDEA51C1FBFB9008B5358 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = F59CDE881C1FBFB9008B5358 /* Info.plist */; };
F59CDEA61C1FBFB9008B5358 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F59CDE891C1FBFB9008B5358 /* main.m */; };
F59CDEA71C1FBFB9008B5358 /* myNavigationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F59CDE8B1C1FBFB9008B5358 /* myNavigationViewController.m */; };
F59CDEA81C1FBFB9008B5358 /* RxLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = F59CDE8E1C1FBFB9008B5358 /* RxLabel.m */; };
F59CDEA91C1FBFB9008B5358 /* RxTextLinkTapView.m in Sources */ = {isa = PBXBuildFile; fileRef = F59CDE901C1FBFB9008B5358 /* RxTextLinkTapView.m */; };
F59CDEB01C1FBFB9008B5358 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F59CDE9E1C1FBFB9008B5358 /* ViewController.m */; };
Expand All @@ -27,10 +26,10 @@
F59CDEC71C1FC6AE008B5358 /* NJKWebViewProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = F59CDEBE1C1FC6AE008B5358 /* NJKWebViewProgress.m */; };
F59CDEC81C1FC6AE008B5358 /* NJKWebViewProgressView.m in Sources */ = {isa = PBXBuildFile; fileRef = F59CDEC01C1FC6AE008B5358 /* NJKWebViewProgressView.m */; };
F59CDEC91C1FC6AE008B5358 /* RxWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F59CDEC21C1FC6AE008B5358 /* RxWebViewController.m */; };
F59CDECA1C1FC6AE008B5358 /* RxWebViewNavigationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F59CDEC41C1FC6AE008B5358 /* RxWebViewNavigationViewController.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
2DE53C3A1CCF04C2006B9162 /* UINavigationController+RxWebViewNavigation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UINavigationController+RxWebViewNavigation.m"; sourceTree = "<group>"; };
F53D31991BDA4FCA002322E1 /* RxWebViewControllerTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RxWebViewControllerTest.app; sourceTree = BUILT_PRODUCTS_DIR; };
F53D31EB1BDB339D002322E1 /* Reveal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Reveal.framework; sourceTree = "<group>"; };
F59CDE7F1C1FBFB9008B5358 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand All @@ -42,8 +41,6 @@
F59CDE871C1FBFB9008B5358 /* icon-140.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon-140.png"; sourceTree = "<group>"; };
F59CDE881C1FBFB9008B5358 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F59CDE891C1FBFB9008B5358 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
F59CDE8A1C1FBFB9008B5358 /* myNavigationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = myNavigationViewController.h; sourceTree = "<group>"; };
F59CDE8B1C1FBFB9008B5358 /* myNavigationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = myNavigationViewController.m; sourceTree = "<group>"; };
F59CDE8D1C1FBFB9008B5358 /* RxLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RxLabel.h; sourceTree = "<group>"; };
F59CDE8E1C1FBFB9008B5358 /* RxLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RxLabel.m; sourceTree = "<group>"; };
F59CDE8F1C1FBFB9008B5358 /* RxTextLinkTapView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RxTextLinkTapView.h; sourceTree = "<group>"; };
Expand All @@ -61,8 +58,6 @@
F59CDEC01C1FC6AE008B5358 /* NJKWebViewProgressView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJKWebViewProgressView.m; sourceTree = "<group>"; };
F59CDEC11C1FC6AE008B5358 /* RxWebViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RxWebViewController.h; sourceTree = "<group>"; };
F59CDEC21C1FC6AE008B5358 /* RxWebViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RxWebViewController.m; sourceTree = "<group>"; };
F59CDEC31C1FC6AE008B5358 /* RxWebViewNavigationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RxWebViewNavigationViewController.h; sourceTree = "<group>"; };
F59CDEC41C1FC6AE008B5358 /* RxWebViewNavigationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RxWebViewNavigationViewController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -98,8 +93,6 @@
F59CDE7E1C1FBFB9008B5358 /* RxWebViewControllerTest */ = {
isa = PBXGroup;
children = (
F59CDE8A1C1FBFB9008B5358 /* myNavigationViewController.h */,
F59CDE8B1C1FBFB9008B5358 /* myNavigationViewController.m */,
F59CDEB41C1FC06B008B5358 /* myNormalViewController.h */,
F59CDEB51C1FC06B008B5358 /* myNormalViewController.m */,
F59CDEB61C1FC06B008B5358 /* myNormalViewController.xib */,
Expand Down Expand Up @@ -138,8 +131,7 @@
F59CDEBC1C1FC6AE008B5358 /* NJKWebViewProgress */,
F59CDEC11C1FC6AE008B5358 /* RxWebViewController.h */,
F59CDEC21C1FC6AE008B5358 /* RxWebViewController.m */,
F59CDEC31C1FC6AE008B5358 /* RxWebViewNavigationViewController.h */,
F59CDEC41C1FC6AE008B5358 /* RxWebViewNavigationViewController.m */,
2DE53C3A1CCF04C2006B9162 /* UINavigationController+RxWebViewNavigation.m */,
);
path = RxWebViewController;
sourceTree = "<group>";
Expand Down Expand Up @@ -181,7 +173,7 @@
F53D31911BDA4FCA002322E1 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0730;
ORGANIZATIONNAME = roxasora;
TargetAttributes = {
F53D31981BDA4FCA002322E1 = {
Expand Down Expand Up @@ -220,7 +212,6 @@
F59CDEB81C1FC06B008B5358 /* myNormalViewController.xib in Resources */,
F59CDEC61C1FC6AE008B5358 /* backItemImage_hl@2x.png in Resources */,
F59CDEA21C1FBFB9008B5358 /* Main.storyboard in Resources */,
F59CDEA51C1FBFB9008B5358 /* Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -234,10 +225,9 @@
F59CDEC71C1FC6AE008B5358 /* NJKWebViewProgress.m in Sources */,
F59CDEA61C1FBFB9008B5358 /* main.m in Sources */,
F59CDE9F1C1FBFB9008B5358 /* AppDelegate.m in Sources */,
2DE53C3B1CCF04C2006B9162 /* UINavigationController+RxWebViewNavigation.m in Sources */,
F59CDEA81C1FBFB9008B5358 /* RxLabel.m in Sources */,
F59CDEB01C1FBFB9008B5358 /* ViewController.m in Sources */,
F59CDEA71C1FBFB9008B5358 /* myNavigationViewController.m in Sources */,
F59CDECA1C1FC6AE008B5358 /* RxWebViewNavigationViewController.m in Sources */,
F59CDEB71C1FC06B008B5358 /* myNormalViewController.m in Sources */,
F59CDEC81C1FC6AE008B5358 /* NJKWebViewProgressView.m in Sources */,
F59CDEA91C1FBFB9008B5358 /* RxTextLinkTapView.m in Sources */,
Expand Down
8 changes: 4 additions & 4 deletions RxWebViewControllerTest/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9060" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="f6J-Gt-hc5">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="f6J-Gt-hc5">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9051"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<scenes>
<!--RxWebViewController-->
Expand Down Expand Up @@ -65,10 +65,10 @@
</objects>
<point key="canvasLocation" x="1135" y="380"/>
</scene>
<!--Rx Web View Navigation View Controller-->
<!--Navigation Controller-->
<scene sceneID="BNI-Fc-N3e">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="f6J-Gt-hc5" customClass="RxWebViewNavigationViewController" sceneMemberID="viewController">
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="f6J-Gt-hc5" sceneMemberID="viewController">
<toolbarItems/>
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics" statusBarStyle="lightContent"/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="EcN-dP-Pot">
Expand Down
13 changes: 0 additions & 13 deletions RxWebViewControllerTest/myNavigationViewController.h

This file was deleted.

37 changes: 0 additions & 37 deletions RxWebViewControllerTest/myNavigationViewController.m

This file was deleted.