Skip to content

Commit

Permalink
Compatible WKWebView. Added sj_considerWebView Property.
Browse files Browse the repository at this point in the history
  • Loading branch information
changsanjiang committed Jan 24, 2018
1 parent ded5626 commit 367be60
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 60 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ Please wait for the example load, or download the project directly.
```Objective-C
@interface UIViewController (SJVideoPlayerAdd)

@property (nonatomic, readonly) UIGestureRecognizerState sj_fullscreenGestureState;

/*!
* Consider `webview`.
* when this property if set, will be enabled system gesture to back last web page, until it can't go back.
*
* 考虑`webview`. 当设置此属性后, 将会`启用手势返回上一个网页`.
**/
@property (nonatomic, weak, readwrite, nullable) WKWebView *sj_considerWebView;

/*!
* The specified area does not trigger gestures. It does not affect other ViewControllers.
* In the array is subview frame.
Expand Down
Binary file not shown.
61 changes: 4 additions & 57 deletions SJBackGRProject/SJBackGRProject/WebTest/WebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,18 @@
#import "WebViewController.h"
#import <Masonry.h>
#import <WebKit/WebKit.h>
#import <SJUIFactory.h>
#import "UIViewController+SJVideoPlayerAdd.h"

@interface WebViewController ()<WKNavigationDelegate>

@property (nonatomic, strong) WKWebView *webView;

@property (nonatomic, strong) UIButton *backBtn;
@property (nonatomic, strong) UIButton *forwardBtn;
@property (nonatomic, strong) UIButton *itemListBtn;

@end

@implementation WebViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];

WKWebViewConfiguration *config = [WKWebViewConfiguration new];
self.webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:config];
Expand All @@ -37,58 +33,9 @@ - (void)viewDidLoad {
}];


[self.view addSubview:self.backBtn];
[self.view addSubview:self.itemListBtn];
[self.view addSubview:self.forwardBtn];

[_backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.bottom.offset(0);
make.width.offset(44);
}];

[_itemListBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.offset(0);
make.bottom.offset(0);
}];
// pop gesture need considers the Web view.
self.sj_considerWebView = self.webView;

[_forwardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.trailing.offset(0);
make.width.offset(44);
}];



// Do any additional setup after loading the view.
}

- (void)clickedBackBtn:(UIButton *)btn {
[_webView goBack];
}

- (void)clickedItemListBtn {
NSLog(@" \n%@ \n- \n%@", _webView.backForwardList.backList, _webView.backForwardList.forwardList);
}

- (void)clickedForwardBtn:(UIButton *)btn {
[_webView goForward];
}

- (UIButton *)backBtn {
if ( _backBtn ) return _backBtn;
_backBtn = [SJUIButtonFactory buttonWithTitle:@"<<" titleColor:[UIColor blueColor] font:[UIFont systemFontOfSize:14] target:self sel:@selector(clickedBackBtn:)];
return _backBtn;
}

- (UIButton *)itemListBtn {
if ( _itemListBtn ) return _itemListBtn;
_itemListBtn = [SJUIButtonFactory buttonWithTitle:@"ItemList" titleColor:[UIColor blueColor] font:[UIFont systemFontOfSize:14] target:self sel:@selector(clickedItemListBtn)];
return _itemListBtn;
}

- (UIButton *)forwardBtn {
if ( _forwardBtn ) return _forwardBtn;
_forwardBtn = [SJUIButtonFactory buttonWithTitle:@">>" titleColor:[UIColor blueColor] font:[UIFont systemFontOfSize:14] target:self sel:@selector(clickedForwardBtn:)];
return _forwardBtn;
}

@end
2 changes: 1 addition & 1 deletion SJFullscreenPopGesture.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "SJFullscreenPopGesture"
s.version = "1.3.1"
s.version = "1.3.2"
s.summary = "fullscreen pop gestures."

# This description is used to generate tags and improve search results.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ - (UIPanGestureRecognizer *)SJ_pan {

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ( self.topViewController.sj_DisableGestures ||
self.childViewControllers.count <= 1 ||
[[self valueForKey:@"_isTransitioning"] boolValue] ) return NO;
[[self valueForKey:@"_isTransitioning"] boolValue] ||
[self.topViewController.sj_considerWebView canGoBack] ) return NO;
else if ( self.childViewControllers.count <= 1 ) return NO;
else return YES;
}

Expand Down
10 changes: 10 additions & 0 deletions SJFullscreenPopGesture/UIViewController+SJVideoPlayerAdd.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@

NS_ASSUME_NONNULL_BEGIN

@class WKWebView;

@interface UIViewController (SJVideoPlayerAdd)

@property (nonatomic, readonly) UIGestureRecognizerState sj_fullscreenGestureState;

/*!
* Consider `webview`.
* when this property if set, will be enabled system gesture to back last web page, until it can't go back.
*
* 考虑`webview`. 当设置此属性后, 将会`启用手势返回上一个网页`.
**/
@property (nonatomic, weak, readwrite, nullable) WKWebView *sj_considerWebView;

/*!
* The specified area does not trigger gestures. It does not affect other ViewControllers.
* In the array is subview frame.
Expand Down
10 changes: 10 additions & 0 deletions SJFullscreenPopGesture/UIViewController+SJVideoPlayerAdd.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "UIViewController+SJVideoPlayerAdd.h"
#import "UINavigationController+SJVideoPlayerAdd.h"
#import <objc/message.h>
#import <WebKit/WKWebView.h>

@implementation UIViewController (SJVideoPlayerAdd)

Expand All @@ -20,6 +21,15 @@ - (void)setSj_fadeArea:(NSArray<NSValue *> *)sj_fadeArea {
objc_setAssociatedObject(self, @selector(sj_fadeArea), sj_fadeArea, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (WKWebView *)sj_considerWebView {
return objc_getAssociatedObject(self, _cmd);
}

- (void)setSj_considerWebView:(WKWebView *)sj_considerWebView {
sj_considerWebView.allowsBackForwardNavigationGestures = YES;
objc_setAssociatedObject(self, @selector(sj_considerWebView), sj_considerWebView, OBJC_ASSOCIATION_ASSIGN);
}

- (NSArray<NSValue *> *)sj_fadeArea {
return objc_getAssociatedObject(self, _cmd);
}
Expand Down

0 comments on commit 367be60

Please sign in to comment.